/* ---- tokens ---- */
:root{
  --bg: #ffffff;
  --bg-soft: #f5f9fc;
  --blue: #1999dc;
  --blue-dark: #147bb3;
  --blue-tint: #e7f4fb;
  --ink: #1c2530;
  --ink-soft: #5b6b7a;
  --ink-faint: #8798a6;
  --line: #e2e8ee;
  --warn: #b3720f;
  --warn-bg: #fbf1de;
  --ok: #1e8a5f;
  --ok-bg: #e6f5ee;
  --danger: #a4380f;
  --danger-dark: #8a2f0c;

  --sans: "Manrope", ui-sans-serif, system-ui, sans-serif;
}

*{ box-sizing: border-box; }
[hidden]{ display: none !important; }

body{
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
}

button{ font-family: inherit; }

/* ---- masthead ---- */
.masthead{
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  display:flex;
  align-items:center;
  justify-content: space-between;
  padding: clamp(0.9rem, 2vw, 1.25rem) clamp(1.25rem, 4vw, 3rem);
  border-bottom: 1px solid var(--line);
}
.masthead__mark{
  display: flex;
  align-items: center;
}
.masthead__logo{
  height: 1.9rem;
  width: auto;
  display: block;
}
.masthead__session{
  display:flex;
  align-items:baseline;
  gap: 1rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
}
#masthead-user{ font-weight: 600; color: var(--ink); }

.link-btn{
  background:none;
  border:none;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0;
  margin: 0;
  font-size: inherit;
  font-weight: 600;
  line-height: inherit;
  vertical-align: baseline;
}
.link-btn:hover{ color: var(--blue); }

/* ---- login ---- */
.login{
  display:grid;
  place-items: center;
  min-height: calc(100dvh - 4.5rem);
  padding: 2rem 1.25rem;
}
.login__panel{
  width: 100%;
  display:flex;
  align-items:center;
  justify-content:center;
}
.login-form{
  width: 100%;
  max-width: 22rem;
  display:flex;
  flex-direction:column;
  gap: 1.3rem;
  background: var(--bg);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(28, 37, 48, 0.04), 0 16px 40px -12px rgba(28, 37, 48, 0.14);
  padding: 2rem;
}
.login-form__head{ margin-bottom: 0.2rem; }
.login-form__title{
  font-weight: 800;
  font-size: 1.4rem;
  line-height: 1.3;
  margin: 0 0 0.4rem;
  letter-spacing: -0.01em;
}
.login-form__subtitle{
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.field{ display:flex; flex-direction:column; gap: 0.45rem; }
.field__label{
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
}
input[type=text], input[type=password], textarea{
  font: inherit;
  padding: 0.75rem 0.9rem;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  transition: border-color 120ms ease-out;
}
input[type=text]:hover, input[type=password]:hover, textarea:hover{
  border-color: color-mix(in srgb, var(--blue) 40%, var(--line));
}
input:focus-visible, textarea:focus-visible, button:focus-visible{
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.btn{
  border: none;
  border-radius: 8px;
  padding: 0.75rem 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease-out, background 120ms ease-out, box-shadow 120ms ease-out;
}
.btn--primary{
  background: var(--blue);
  color: #fff;
  box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--blue) 70%, transparent);
}
.btn--primary:hover{ background: var(--blue-dark); }
.btn--primary:active{ transform: scale(0.98); }
.btn--secondary{ background: var(--bg-soft); color: var(--ink); }
.btn--secondary:hover{ background: var(--line); }
.btn--block{ width: 100%; margin-top: 0.3rem; }
.btn:disabled{ opacity: 0.6; cursor: not-allowed; box-shadow: none; }

.form-error{
  margin:0;
  color: #a4380f;
  font-size: 0.88rem;
  background: #fdeee7;
  border: 1px solid #f5cdb8;
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
}

.field-hint{ margin: 0.3rem 0 0; font-size: 0.82rem; }
.field-hint--ok{ color: var(--ok); }
.field-hint--bad{ color: var(--danger); }

/* ---- app shell: sidebar + content ---- */
.shell{
  display: flex;
  align-items: stretch;
  min-height: calc(100dvh - 4.5rem);
}
.shell__content{
  flex: 1;
  min-width: 0;
}

/* wraps .sidebar so the divider line spans the full content height while
   the nav itself stays shrink-wrapped — required for position:sticky to
   have room to move within */
.sidebar-rail{
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  border-right: 1px solid var(--line);
}

.sidebar{
  position: sticky;
  top: 4.5rem;
  max-height: calc(100dvh - 4.5rem);
  overflow-y: auto;
  width: 15rem;
  padding: 1.1rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition: width 160ms ease-out;
}
.sidebar--collapsed{ width: 4.2rem; }

.sidebar__toggle{
  align-self: flex-end;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 6px;
  background: var(--bg-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.sidebar__toggle:hover{ background: var(--blue-tint); }
.sidebar--collapsed .sidebar__toggle{ align-self: center; }
.sidebar__toggle-icon{
  width: 0.55rem;
  height: 0.55rem;
  border-left: 2px solid var(--ink-soft);
  border-bottom: 2px solid var(--ink-soft);
  transform: rotate(45deg);
  transition: transform 160ms ease-out;
}
.sidebar--collapsed .sidebar__toggle-icon{ transform: rotate(225deg); }

.sidebar__list{
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.sidebar__item{
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.55rem;
  border: none;
  background: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.9rem;
  text-align: left;
  text-decoration: none;
}
.sidebar__item:hover{ background: var(--bg-soft); color: var(--ink); }
.sidebar__item.is-active{ background: var(--blue-tint); color: var(--blue-dark); }
.sidebar__icon{
  flex-shrink: 0;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 6px;
  background: var(--bg-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
}
.sidebar__item.is-active .sidebar__icon{ background: var(--blue); color: #fff; }
.sidebar__icon svg{ width: 60%; height: 60%; }
.sidebar--collapsed .sidebar__label{ display: none; }
.sidebar--collapsed .sidebar__item{ justify-content: center; padding: 0.5rem; }

/* ---- home menu ---- */
.home{
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: clamp(2.5rem, 8vw, 6rem) 1.5rem;
}
.home__title{
  margin: 0 0 0.4rem;
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  font-weight: 800;
  letter-spacing: -0.01em;
}
.home__subtitle{ margin: 0 0 2.2rem; color: var(--ink-soft); }
.home__grid{
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 16rem));
  gap: 1.25rem;
  justify-content: center;
  width: 100%;
  max-width: 60rem;
}
.tool-card{
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.6rem;
  text-align: left;
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  transition: transform 140ms ease-out, box-shadow 140ms ease-out, border-color 140ms ease-out;
}
.tool-card:hover{
  transform: translateY(-2px);
  box-shadow: 0 12px 28px -14px rgba(28, 37, 48, 0.18);
  border-color: color-mix(in srgb, var(--blue) 35%, var(--line));
}
.tool-card__icon{
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 8px;
  background: var(--blue-tint);
  color: var(--blue-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
}
.tool-card__icon svg{ width: 55%; height: 55%; }
.tool-card__name{ font-weight: 700; font-size: 1.05rem; }
.tool-card__desc{ color: var(--ink-soft); font-size: 0.88rem; }

/* ---- desk (a tool's own layout) ---- */
.tool-back{
  width: fit-content;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  padding: 0;
}
.tool-back:hover{ color: var(--blue); }

.desk{
  display:flex;
  flex-direction: column;
  gap: clamp(1.25rem, 2.5vw, 1.75rem);
  padding: clamp(1.25rem, 3vw, 2.5rem) clamp(1.25rem, 4vw, 3rem);
}

.submit-panel{
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.4rem;
  display:flex;
  flex-direction:column;
  gap: 0.9rem;
}
.submit-panel__head{ display:flex; flex-direction:column; gap: 0.35rem; }
.submit-panel__title{
  font-weight: 700;
  font-size: 1.1rem;
  margin: 0;
}
.submit-panel__hint{
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.88rem;
}
#validate-form{ display:flex; flex-direction: column; gap: 0.8rem; }
#validate-submit{ align-self: flex-start; }
.url-count{
  display: inline-block;
  margin-left: 0.4rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-faint);
  white-space: nowrap;
}
.url-count--over{ color: #a4380f; }
textarea{ resize: vertical; font-family: var(--sans); background: var(--bg); }

.url-issues{
  list-style: none;
  margin: -0.6rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.url-issue{
  display:flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  font-size: 0.82rem;
}
.url-issue__text{
  overflow-wrap: anywhere;
  color: var(--ink-soft);
}
.url-issue__tag{
  flex-shrink: 0;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}
.url-issue--invalid{ background: #fdeee7; }
.url-issue--invalid .url-issue__tag{ background: #f5cdb8; color: #a4380f; }
.url-issue--dup{ background: var(--warn-bg); }
.url-issue--dup .url-issue__tag{ background: color-mix(in srgb, var(--warn) 30%, var(--warn-bg)); color: var(--warn); }

.results{
  display:flex;
  flex-direction:column;
  gap: 1.75rem;
  min-width: 0;
}

.empty-state{
  padding: 2.5rem 1rem;
  color: var(--ink-faint);
  border: 1px dashed var(--line);
  border-radius: 10px;
  text-align: center;
}
.empty-state p{ margin: 0.25rem 0; }
.empty-state__hint, .results-empty-hint{ font-size: 0.88rem; }

/* summary strip */
.summary{
  display:grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.summary__item{
  display:flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 1.1rem 1.3rem;
  border-left: 1px solid var(--line);
}
.summary__item:first-child{ border-left: none; }
.summary__value{ font-size: 1.75rem; font-weight: 800; line-height: 1; color: var(--ink); }
.summary__label{
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}
.summary__item--new .summary__value{ color: var(--blue-dark); }
.summary__item--warn .summary__value{ color: var(--warn); }
.summary__item--ok .summary__value{ color: var(--ok); }

@media (max-width: 560px){
  .summary{ grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary__item:nth-child(2n+1){ border-left: none; }
  .summary__item:nth-child(n+3){ border-top: 1px solid var(--line); }
}

/* result sections */
.section{ display:flex; flex-direction:column; gap: 0.9rem; }
.insert-bar{ display:flex; }

/* insert success/error popup */
.modal-backdrop{
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(28, 37, 48, 0.45);
}
.modal{
  position: relative;
  width: 100%;
  max-width: 26rem;
  background: var(--bg);
  border-radius: 12px;
  padding: 1.5rem 1.75rem 1.75rem;
  box-shadow: 0 24px 60px -20px rgba(28, 37, 48, 0.4);
}
.modal__close{
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 1.8rem;
  height: 1.8rem;
  border: none;
  background: none;
  border-radius: 6px;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--ink-faint);
  cursor: pointer;
}
.modal__close:hover{ background: var(--bg-soft); color: var(--ink); }
.modal__message{
  margin: 0.5rem 0 0;
  padding-right: 0.5rem;
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.5;
}
.modal--success .modal__message{ color: var(--ok); }
.modal--error .modal__message{ color: #a4380f; }
.modal__actions{ display:flex; justify-content:flex-end; gap:0.6rem; margin-top:1.1rem; }

/* full-page block while an API call is in flight */
.busy-overlay{
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(28, 37, 48, 0.15);
  cursor: wait;
}
.busy-overlay__spinner{
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.4);
  border-top-color: var(--blue);
  animation: busy-spin 700ms linear infinite;
}
@keyframes busy-spin{ to{ transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce){
  .busy-overlay__spinner{ animation-duration: 1400ms; }
}
.modal__list{
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  max-height: 12rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.modal__list li{
  font-size: 0.85rem;
  color: var(--ink-soft);
  background: var(--bg-soft);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  overflow-wrap: anywhere;
}
.modal__list--numbered{ list-style: decimal; padding-left: 1.25rem; }
.modal__list--numbered li{ background: none; padding: 0.15rem 0; }
.section__title{
  font-size: 1.02rem;
  font-weight: 700;
  margin: 0;
  display:flex;
  align-items:center;
  gap: 0.5rem;
}
.section__title .tag{
  display: inline-flex;
  align-items: center;
  line-height: 1;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.3rem 0.45rem;
  border-radius: 4px;
}
.section--ok .tag{ background: var(--ok-bg); color: var(--ok); }
.section--warn .tag{ background: var(--warn-bg); color: var(--warn); }
.section--new .tag{ background: var(--blue-tint); color: var(--blue-dark); }

.list{ display:flex; flex-direction:column; gap: 0.6rem; list-style:none; margin:0; padding:0; }

.row{
  display:flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-soft);
}
.row__url{
  font-size: 0.9rem;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}
.row__action{
  white-space: nowrap;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--blue);
  text-decoration: none;
}
.row__action:hover{ color: var(--blue-dark); }
.row__meta{
  font-size: 0.85rem;
  color: var(--ink-faint);
  white-space: nowrap;
}

.clipping{
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.1rem 1.2rem;
  background: var(--bg);
  box-shadow: 0 1px 2px rgba(28, 37, 48, 0.03), 0 10px 24px -20px rgba(28, 37, 48, 0.22);
}

/* editable clipping */
.clipping--edit{ display: flex; flex-direction: column; gap: 0.75rem; }
.clipping__index{
  align-self: flex-start;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--blue-tint);
  color: var(--blue-dark);
}
.list .clipping:nth-child(even) .clipping__index{ background: var(--ok-bg); color: var(--ok); }
.edit-field{ display: flex; flex-direction: column; gap: 0.35rem; }
.edit-field__control{ display: flex; flex-direction: column; gap: 0.35rem; }
.edit-field__label{
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}
.edit-field input, .edit-field textarea{
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  transition: border-color 120ms ease-out;
}
.edit-field input:hover, .edit-field textarea:hover{
  border-color: color-mix(in srgb, var(--blue) 40%, var(--line));
}
.edit-field textarea{ resize: vertical; }
.edit-field input.is-invalid{ border-color: #d0553a; }
.edit-field__error{
  margin: 0;
  color: #a4380f;
  font-size: 0.8rem;
}
.edit-field input[readonly]{
  background: var(--bg-soft);
  color: var(--ink-soft);
  cursor: default;
}
.edit-field-row{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* media search dropdown */
.media-select{ position: relative; }
.media-select__input{
  width: 100%;
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
}
.media-select__input:hover{ border-color: color-mix(in srgb, var(--blue) 40%, var(--line)); }
.media-select__list{
  position: absolute;
  z-index: 10;
  top: calc(100% + 0.3rem);
  left: 0;
  right: 0;
  max-height: 12rem;
  overflow-y: auto;
  margin: 0;
  padding: 0.3rem;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 28px -14px rgba(28, 37, 48, 0.25);
}
.media-select__option{
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
}
.media-select__option:hover{ background: var(--blue-tint); color: var(--blue-dark); }
.media-select__status{
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
  color: var(--ink-faint);
}
.clipping__preview{
  max-width: 100%;
  max-height: 16rem;
  width: auto;
  border-radius: 8px;
  border: 1px solid var(--line);
  object-fit: contain;
  align-self: flex-start;
}
@media (max-width: 480px){
  .edit-field-row{ grid-template-columns: 1fr; }
}

/* ---- motion ---- */
@keyframes rise{
  from{ opacity: 0; transform: translateY(10px); }
  to{ opacity: 1; transform: translateY(0); }
}
.results > *{
  animation: rise 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.results > *:nth-child(2){ animation-delay: 40ms; }
.results > *:nth-child(3){ animation-delay: 80ms; }
.results > *:nth-child(4){ animation-delay: 120ms; }

@media (prefers-reduced-motion: reduce){
  .results > *{ animation: none; }
  .btn{ transition: none; }
}

/* ---- responsive ---- */
@media (max-width: 700px){
  .shell{ flex-direction: column; }
  .sidebar-rail{
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .sidebar{
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    overflow-x: auto;
  }
  .sidebar--collapsed{ width: 100%; }
  .sidebar__toggle{ display: none; }
  .sidebar__list{ flex-direction: row; }
  .sidebar__label{ display: none; }
}

/* ---- manage accounts ---- */
.accounts-table{
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.accounts-table th, .accounts-table td{
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.accounts-table__actions{ display: flex; gap: 0.4rem; }
.accounts-table__actions .btn--small{ min-width: 5.5rem; text-align: center; }
.status-badge{
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}
.status-badge--active{ background: var(--ok-bg); color: var(--ok); }
.status-badge--inactive{ background: var(--bg-soft); color: var(--ink-soft); }
.btn--small{ padding: 0.35rem 0.65rem; font-size: 0.8rem; }
.btn--danger{ background: var(--danger); color: #fff; }
.btn--danger:hover{ background: var(--danger-dark); }
.account-form{ display: flex; flex-direction: column; gap: 0.9rem; }
.account-form__actions{ display: flex; align-items: center; gap: 0.9rem; }
.edit-field select{
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
}
#accounts-content{ display: flex; flex-direction: column; gap: clamp(1.25rem, 2.5vw, 1.75rem); }
.accounts-search input{
  width: 100%;
  max-width: 22rem;
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
}
.accounts-search input:hover{ border-color: color-mix(in srgb, var(--blue) 40%, var(--line)); }
.sort-header{
  border: none;
  background: none;
  font: inherit;
  font-weight: 700;
  padding: 0;
  cursor: pointer;
  color: inherit;
}
.sort-header:hover{ color: var(--blue); }
.pagination{ display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; justify-content: center; }
