:root {
  --background: #f5f7fb;
  --foreground: #0f172a;
  --card: #ffffff;
  --secondary: #f8fafc;
  --muted: #64748b;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --primary: #111827;
  --primary-foreground: #ffffff;
  --danger: #b91c1c;
  --shadow-soft: 0 1px 2px rgba(15, 23, 42, 0.05), 0 6px 16px rgba(15, 23, 42, 0.04);
  --shadow-strong: 0 16px 40px rgba(15, 23, 42, 0.12);
  --sidebar-width: clamp(184px, 15vw, 216px);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--foreground);
  background:
    radial-gradient(1200px 640px at 0% -10%, #ffffff 0%, transparent 70%),
    radial-gradient(1200px 640px at 100% -15%, #eef2ff 0%, transparent 66%),
    var(--background);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-layout {
  min-height: 100vh;
  display: flex;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  padding: 16px 12px;
  border-right: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: #111827;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 0.94rem;
}

.brand span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.76rem;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav-item {
  border-radius: 12px;
  padding: 10px 12px;
  color: #334155;
  font-size: 0.9rem;
  font-weight: 650;
}

.nav-item.active {
  background: #111827;
  color: #ffffff;
  box-shadow: var(--shadow-soft);
}

.muted-link {
  color: #64748b;
}

.main {
  width: 100%;
  min-height: 100vh;
  padding: 26px 22px 190px;
  margin-left: var(--sidebar-width);
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 18px;
}

.page-head h1 {
  margin: 0;
  font-size: clamp(1.7rem, 3vw, 2.35rem);
  letter-spacing: 0;
}

.page-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.96rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-card,
.ig-card,
.login-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow-soft);
}

.metric-card {
  display: grid;
  gap: 5px;
  padding: 14px 16px;
}

.metric-title,
.metric-hint {
  color: var(--muted);
  font-size: 0.78rem;
}

.metric-title {
  font-weight: 700;
  text-transform: uppercase;
}

.metric-value {
  font-size: 1.6rem;
  line-height: 1;
}

.metric-text {
  font-size: 1rem;
  line-height: 1.35;
}

.notice {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid #bfdbfe;
  border-radius: 14px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 0.9rem;
}

.notice.error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}

.hidden {
  display: none !important;
}

.ig-canvas {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(245px, 1fr));
  gap: 14px;
  align-items: start;
}

.ig-card {
  overflow: hidden;
}

.ig-card-image,
.draft-image {
  width: 100%;
  aspect-ratio: 4 / 5;
  display: block;
  object-fit: cover;
  background: #e5e7eb;
}

.ig-card-image {
  cursor: zoom-in;
}

.ig-card-body {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.card-topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #f8fafc;
  color: #334155;
  font-size: 0.75rem;
  font-weight: 750;
}

.pill-soft {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
}

.pill-ok {
  border-color: #bbf7d0;
  background: #f7fee7;
  color: #166534;
}

.pill-danger {
  border-color: #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}

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

.text-sm {
  font-size: 0.84rem;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn,
.icon-chip {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #ffffff;
  color: #334155;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 700;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.btn:hover,
.icon-chip:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
}

.btn-primary {
  border-color: #111827;
  background: #111827;
  color: #ffffff;
}

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

.btn:disabled {
  opacity: 0.56;
  cursor: not-allowed;
  transform: none;
}

.icon-chip {
  width: 34px;
  min-height: 34px;
  padding: 0;
}

.ig-dock-wrap {
  position: fixed;
  left: var(--sidebar-width);
  right: 0;
  bottom: 0;
  z-index: 30;
  padding: 14px 20px 18px;
  pointer-events: none;
}

.ig-dock {
  width: min(980px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.18);
  backdrop-filter: blur(16px);
  pointer-events: auto;
}

.ig-dock-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.textarea,
.select,
.input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #ffffff;
  color: var(--foreground);
  padding: 10px 12px;
  outline: none;
  font-size: 0.92rem;
}

.textarea:focus,
.select:focus,
.input:focus {
  border-color: #94a3b8;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.18);
}

.textarea {
  min-height: 96px;
  resize: vertical;
}

.select {
  width: auto;
  min-width: 108px;
}

.compact {
  min-width: 76px;
}

.progress-track {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: #111827;
  transition: width 180ms ease;
}

.draft-image {
  display: grid;
  place-items: center;
  color: #64748b;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid #cbd5e1;
  border-top-color: #111827;
  border-radius: 999px;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.preview-dialog {
  width: min(920px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow-strong);
  padding: 16px;
}

.preview-dialog::backdrop {
  background: rgba(15, 23, 42, 0.48);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.dialog-head h2,
.dialog-head p {
  margin: 0;
}

.dialog-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.85rem;
}

#preview-image {
  max-width: 100%;
  max-height: 72vh;
  display: block;
  margin: 0 auto;
  border-radius: 12px;
  object-fit: contain;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
}

.login-shell {
  width: min(420px, calc(100vw - 32px));
}

.login-card {
  display: grid;
  gap: 22px;
  padding: 24px;
}

.login-card h1 {
  margin: 4px 0 0;
  font-size: 2rem;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-form label {
  display: grid;
  gap: 6px;
  color: #334155;
  font-size: 0.84rem;
  font-weight: 700;
}

.login-form input {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 0.86rem;
}

@media (max-width: 900px) {
  .sidebar {
    display: none;
  }

  .main,
  .ig-dock-wrap {
    margin-left: 0;
    left: 0;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .main {
    padding: 20px 14px 230px;
  }

  .page-head {
    flex-direction: column;
  }

  .metric-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .ig-canvas {
    grid-template-columns: minmax(0, 1fr);
  }

  .ig-dock-wrap {
    padding: 10px;
  }

  .select,
  .ig-dock-row .btn {
    flex: 1 1 120px;
  }
}
