/* ------------------------------
   Codeforces Solutions – Styles
   Clean, responsive, accessible UI
   ------------------------------ */

/* 1) Design tokens */
:root {
  /* Color system */
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --ring: #3a8dde33; /* focus ring (20%) */
  --primary: #3a8dde;
  --primary-600: #2f78c1;
  --primary-700: #27639f;
  --success: #16a34a;
  --danger: #dc2626;
  --shadow: 0 3px 14px rgba(0, 0, 0, 0.06), 0 8px 28px rgba(0, 0, 0, 0.06);

  /* Radii & sizing */
  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 14px;
  --content-max: 1100px;
}

/* 2) Base reset */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html:focus-within {
  scroll-behavior: smooth;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, "Open Sans", "Inter",
    "Tajawal", Helvetica, Arial, sans-serif;
  line-height: 1.55;
}
img,
svg {
  display: block;
  max-width: 100%;
}
button {
  font: inherit;
}

/* 3) Header */
header {
  display: grid;
  place-items: center;
  text-align: center;
  gap: 0.45rem;
  padding: 2.25rem 1rem 1.6rem;
  color: #fff;
  background: linear-gradient(120deg, #155799, #159957);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 2px 16px rgba(58, 141, 222, 0.08);
}
header .logo {
  font-size: 2rem;
  line-height: 1;
}
header h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2.5vw, 1.9rem);
}
header .description {
  margin: 0;
  opacity: 0.9;
  font-size: 0.95rem;
}

/* Header bio and actions */
header .bio {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
  opacity: 0.9;
}
header .header-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  margin-top: 0.6rem;
  flex-wrap: wrap;
}
header .header-actions .btn {
  height: 40px;
  padding-inline: 1rem;
}

/* Ensure anchor buttons never show underlines */
.btn {
  text-decoration: none;
}

/* Enhanced styles for header buttons */
header .btn {
  /* remove visible border line */
  border: none;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset,
    0 2px 8px rgba(0, 0, 0, 0.15);
  backdrop-filter: saturate(120%) blur(0.5px);
}
header .btn:hover {
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 4px 14px rgba(0, 0, 0, 0.22);
}
header .btn:active {
  transform: translateY(1px);
}

/* GitHub button */
.btn-github {
  background: linear-gradient(180deg, #24292e, #111418);
  border: none; /* remove line */
}
.btn-github::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 0.4rem;
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="%23fff"><path d="M8 0C3.58 0 0 3.58 0 8a8 8 0 005.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27s1.36.09 2 .27c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>')
    no-repeat 50% 50%;
  background: #fff;
}

/* Portfolio button */
.btn-portfolio {
  background: #ffffff;
  color: #0f172a;
  border: none; /* remove line */
}
.btn-portfolio:hover {
  background: color-mix(in oklab, #fff 94%, black 6%);
}
.btn-portfolio:active {
  background: color-mix(in oklab, #fff 88%, black 12%);
}
.btn-portfolio::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 0.4rem;
  background: #0f172a;
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23000"><path d="M10 2H3a1 1 0 00-1 1v7h8V2zM22 10V3a1 1 0 00-1-1h-7v8h8zM10 22v-8H2v7a1 1 0 001 1h7zM22 22a1 1 0 001-1v-7h-8v8h7z"/></svg>')
    no-repeat 50% 50%;
}

@media (max-width: 520px) {
  header .header-actions {
    justify-content: center;
  }
}

/* 4) Main container helpers */
main {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 1rem;
}

/* Prevent background scroll when modal is open */
body.modal-open {
  overflow: hidden;
}

/* 5) Controls (search + admin) */
.controls {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto; /* search | admin */
  grid-template-areas: "search admin";
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  margin: 0.6rem auto 1rem;
  max-width: var(--content-max);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
#search {
  grid-area: search;
  min-height: 42px;
}
#adminBtn {
  grid-area: admin;
  min-height: 42px;
}

#search {
  appearance: none;
  width: 100%;
  padding: 0.7rem 0.9rem 0.7rem 2.25rem; /* room for icon */
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%239AA4B2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>");
  background-repeat: no-repeat;
  background-position: 0.75rem 50%;
  background-size: 18px 18px;
}
#search::placeholder {
  color: var(--muted);
}
#search:focus {
  outline: none;
  box-shadow: 0 0 0 0.2rem var(--ring);
  border-color: transparent;
}

@media (max-width: 640px) {
  .controls {
    grid-template-columns: 1fr;
    grid-template-areas: "search" "admin";
  }
}

/* 6) Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-weight: 700;
  border: 1px solid transparent;
  color: #fff;
  background: var(--primary);
  transition: background 0.15s ease, transform 0.06s ease, box-shadow 0.15s ease;
}
.btn:hover {
  background: var(--primary-600);
  text-decoration: none;
}
.btn:active {
  transform: translateY(1px);
  background: var(--primary-700);
}
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 0.2rem var(--ring);
}
.btn[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: color-mix(in oklab, var(--surface) 92%, black 8%);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: transparent;
}
.btn-ghost:hover {
  background: color-mix(in oklab, var(--surface) 88%, black 12%);
}

/* 7) Table card */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin: 0 auto 1.25rem;
  max-width: var(--content-max);
  overflow: auto;
}
.table-wrap[tabindex="0"]:focus {
  outline: none;
  box-shadow: 0 0 0 0.2rem var(--ring);
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
}
.table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: color-mix(in oklab, var(--surface) 92%, black 8%);
  color: var(--text);
  text-align: left;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.table-wrap thead th:first-child {
  width: 120px;
}
.table-wrap thead th:nth-child(3),
.table-wrap thead th:nth-child(4) {
  width: 160px;
}

.table-wrap tbody td {
  padding: 0.7rem 1rem;
  border-top: 1px solid var(--border);
}
.table-wrap tbody tr:nth-child(odd) {
  background: color-mix(in oklab, var(--surface) 96%, black 4%);
}
.table-wrap tbody tr:hover {
  background: color-mix(in oklab, var(--surface) 92%, black 8%);
}

/* Sort indicators */
.table-wrap thead th[data-sort] {
  cursor: pointer;
  user-select: none;
}
.table-wrap thead th[data-sort][data-dir="asc"]::after {
  content: " \25B2";
}
.table-wrap thead th[data-sort][data-dir="desc"]::after {
  content: " \25BC";
}

/* Links */
.table-wrap a {
  color: var(--primary);
  font-weight: 600;
}
.table-wrap a:hover {
  text-decoration: underline;
}

/* 8) Modal (Add/Edit) */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(15, 23, 42, 0.6);
  padding: clamp(0.75rem, 2vw, 1rem);
  backdrop-filter: blur(3px);
  z-index: 1000; /* ensure overlay sits above sticky headers */
}
.modal.open {
  display: grid;
}
.modal[aria-hidden="true"] {
  display: none !important;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal .modal-content {
  width: min(600px, 92vw);
  max-height: min(80vh, 780px);
  overflow: auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow), 0 10px 40px rgba(0, 0, 0, 0.12);
  padding: 1.25rem;
  animation: modal-in 160ms ease-out;
  position: relative; /* create stacking context above overlay */
  z-index: 1001;
  overscroll-behavior: contain; /* don't scroll the page behind while scrolling content */
}
.modal .modal-content h2 {
  margin: 0 0 0.9rem;
  font-size: 1.15rem;
  line-height: 1.25;
}
.modal .modal-content form {
  display: grid;
  gap: 0.75rem;
}
.modal label {
  display: grid;
  gap: 0.35rem;
  margin: 0.25rem 0;
  font-weight: 600;
}
.modal input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease,
    background-color 0.15s ease;
}
.modal input:hover {
  border-color: color-mix(in oklab, var(--primary) 35%, var(--border) 65%);
}
.modal input::placeholder {
  color: var(--muted);
}
.modal input:focus {
  outline: none;
  box-shadow: 0 0 0 0.2rem var(--ring);
  border-color: transparent;
}
.modal .modal-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

/* 9) Toast */
.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.6rem 0.8rem;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* 10) Admin badge */
#adminBadge {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  background: color-mix(in oklab, var(--success) 92%, black 8%);
  color: #083b17;
  border: 1px solid color-mix(in oklab, var(--success) 60%, black 40%);
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  font-weight: 700;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  display: none;
  z-index: 10;
}
body[data-admin="true"] #adminBadge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

/* 11) A11y helpers */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Improve visible focus for interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
.table-wrap[tabindex="0"]:focus {
  outline: none;
  box-shadow: 0 0 0 0.2rem var(--ring);
  border-color: transparent;
}

/* 12) Footer */
footer {
  text-align: center;
  color: var(--muted);
  padding: 1.25rem;
}

/* 13) Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
