*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  overflow-x: clip;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

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

a {
  color: var(--accent);
}

.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

/* Auth View */
.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-sm);
}

.brand-mark {
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--ink);
  margin: 0 0 6px;
}

.auth-subtitle {
  margin: 0 0 24px;
  color: var(--ink-muted);
  font-size: 0.9375rem;
}

/* App Shell */
.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.workspace-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.workspace-label {
  font-size: 0.8125rem;
  color: var(--ink-muted);
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-btn {
  width: 100%;
  text-align: start;
  border: 1px solid transparent;
  background: transparent;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--ink-muted);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: background-color 120ms ease, color 120ms ease;
}

.nav-btn:hover {
  background: var(--surface-muted);
  color: var(--ink);
}

.nav-btn[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.875rem;
  color: var(--ink-muted);
}

.main-area {
  padding: 28px 32px;
  max-width: 1280px;
  width: 100%;
  min-width: 0;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 650;
  overflow-wrap: break-word;
  min-width: 0;
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.btn:hover {
  background: var(--surface-muted);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--surface);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--surface);
}

.btn-danger:hover {
  background: var(--danger-soft);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.8125rem;
}

.btn-full {
  width: 100%;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.kpi-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
}

.kpi-label {
  font-size: 0.8125rem;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  margin-bottom: 20px;
}

.section-heading {
  margin: 0 0 14px;
  font-size: 1rem;
  font-weight: 600;
}

/* Filters */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

/* Responsive Data Table (modern-web-guidance: responsive-table) */
.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(560px, 72vh);
  container-type: inline-size;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9375rem;
}

table caption {
  text-align: start;
  padding: 12px 16px;
  font-size: 0.875rem;
  color: var(--ink-muted);
  border-bottom: 1px solid var(--border);
}

thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  background: var(--surface-muted);
}

th,
td {
  padding: 11px 14px;
  text-align: start;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

thead th {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--ink-muted);
  white-space: nowrap;
}

tbody th {
  position: sticky;
  inset-inline-start: 0;
  z-index: 1;
  background: var(--surface);
  font-weight: 600;
}

tbody tr:last-child th,
tbody tr:last-child td {
  border-bottom: 0;
}

@container (width < 640px) {
  table,
  caption,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
    box-sizing: border-box;
  }

  thead {
    display: none;
  }

  tr {
    margin-block-end: 12px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 8px;
  }

  tbody th {
    position: sticky;
    inset-block-start: 0;
    z-index: 2;
    background: var(--surface-muted);
  }

  td {
    border-bottom: 0;
    padding: 6px 14px;
  }

  td[data-label]::before {
    content: attr(data-label) ": ";
    font-weight: 600;
    color: var(--ink-muted);
  }
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  background: var(--surface-muted);
  color: var(--ink-muted);
  white-space: nowrap;
}

.badge-ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

/* Forms & Validation (modern-web-guidance: validate-input-after-interaction) */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
}

.field label {
  font-size: 0.875rem;
  font-weight: 500;
}

.hint {
  font-size: 0.8125rem;
  color: var(--ink-subtle);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 0.9375rem;
}

textarea {
  min-height: 76px;
  resize: vertical;
}

:is(input, select, textarea):is(:user-invalid, .user-invalid-fallback) {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.error-msg {
  display: none;
  color: var(--danger);
  font-size: 0.8125rem;
}

:is(input, select, textarea):is(:user-invalid, .user-invalid-fallback) + .error-msg {
  display: block;
}

.banner {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.875rem;
  border: 1px solid transparent;
}

.banner-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger);
}

.banner-ok {
  background: var(--ok-soft);
  color: var(--ok);
  border-color: var(--ok);
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0;
  color: var(--ink-subtle);
  font-size: 0.8125rem;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.empty-state {
  padding: 36px 20px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.9375rem;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

/* Native Modal Dialog (modern-web-guidance: dialog) */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  width: min(520px, calc(100% - 32px));
  max-height: 90dvh;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}

dialog.dialog-wide {
  width: min(1080px, calc(100% - 32px));
  max-height: 92dvh;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(22, 27, 23, 0.45);
  overflow: hidden;
  overscroll-behavior: contain;
}

.dialog-body {
  padding: 22px 24px;
  overflow-y: auto;
  max-height: 85dvh;
}

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

.dialog-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 650;
}

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

.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* Strategy Hero & Collapsible Sections */
.strategy-hero {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 20px 22px;
  margin-bottom: 20px;
}

.strategy-hero-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.strategy-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.strategy-meta-box {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.strategy-meta-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  margin-bottom: 4px;
}

.strategy-meta-val {
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.section-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 10px;
}

.section-bar-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
}

/* Content Studio Controls & Toggles */
.studio-controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.studio-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.studio-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.segmented {
  display: inline-flex;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.segmented .btn {
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 6px 12px;
  font-size: 0.875rem;
}

.segmented .btn.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.btn-toggle {
  padding: 5px 10px;
  font-size: 0.8125rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink-muted);
  cursor: pointer;
}

.btn-toggle.active {
  background: var(--brand, #14532d);
  border-color: var(--brand, #14532d);
  color: #fff;
  font-weight: 500;
}

.month-nav {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.month-label {
  min-width: 140px;
  text-align: center;
  font-weight: 650;
  font-size: 1rem;
  text-transform: capitalize;
}

/* Channel Colors */
.ch-pill {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.ch-linkedin { background: #dbeafe; color: #1d4ed8; }
.ch-instagram { background: #fce7f3; color: #be185d; }
.ch-facebook { background: #e0e7ff; color: #3730a3; }
.ch-youtube { background: #fee2e2; color: #b91c1c; }
.ch-x { background: #e5e7eb; color: #111827; }
.ch-threads { background: #f3e8ff; color: #6b21a8; }

/* Calendar Grid */
.cal-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 20px;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.cal-head {
  background: var(--surface-muted);
  padding: 8px 10px;
  font-size: 0.8125rem;
  font-weight: 650;
  color: var(--ink-muted);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: center;
}

.cal-head:nth-child(7n) {
  border-right: 0;
}

.cal-cell {
  min-height: 118px;
  padding: 6px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
}

.cal-cell:nth-child(7n) {
  border-right: 0;
}

.cal-cell.other-month {
  background: var(--surface-muted);
  opacity: 0.58;
}

.cal-cell.today {
  background: #f0fdf4;
  box-shadow: inset 0 0 0 2px #15803d;
}

.cal-day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8125rem;
  font-weight: 650;
  color: var(--ink-muted);
  margin-bottom: 2px;
}

.cal-cell.today .cal-day-num {
  background: #15803d;
  color: #fff;
  padding: 1px 6px;
  border-radius: 999px;
}

.cal-chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 5px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  cursor: pointer;
  font-size: 0.77rem;
  line-height: 1.25;
  transition: border-color 0.12s ease, transform 0.12s ease;
}

.cal-chip:hover {
  border-color: var(--brand, #14532d);
  transform: translateY(-1px);
}

.cal-chip.is-approved {
  border-left: 3px solid #15803d;
}

.cal-chip.is-published {
  border-left: 3px solid #0284c7;
  background: #f0f9ff;
}

.cal-chip-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.cal-chip-title {
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Text / List Content Plan View */
.plan-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 20px;
}

.plan-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
}

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

.plan-card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
}

.plan-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.plan-pubs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.plan-pub-box {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--surface-muted);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.plan-pub-body {
  font-size: 0.875rem;
  line-height: 1.5;
  white-space: pre-wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  max-height: 220px;
  overflow: auto;
}

/* Field Help Tooltip (?) */
.field {
  position: relative;
}

.field label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.help-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  border-radius: 999px;
  background: var(--surface-muted, #f3f4f6);
  border: 1px solid var(--border);
  color: var(--ink-muted);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  user-select: none;
  flex-shrink: 0;
}

.help-tip:hover,
.help-tip:focus-visible {
  background: var(--brand, #14532d);
  border-color: var(--brand, #14532d);
  color: #fff;
  outline: none;
}

.help-tip-bubble {
  position: absolute;
  top: 26px;
  left: 0;
  right: 0;
  z-index: 60;
  width: auto;
  max-width: 100%;
  padding: 8px 11px;
  border-radius: 8px;
  background: #161b17;
  color: #f8fafc;
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.4;
  white-space: normal;
  text-align: left;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-3px);
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0.14s ease;
  pointer-events: none;
}

.help-tip-right .help-tip-bubble {
  left: auto;
  right: 0;
  width: min(260px, 100%);
}

.help-tip:hover .help-tip-bubble,
.help-tip:focus-visible .help-tip-bubble {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

@media (max-width: 900px) {
  .cal-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .cal-head {
    display: none;
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-inline-end: 0;
    border-bottom: 1px solid var(--border);
  }

  .nav-list {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .nav-btn {
    width: auto;
  }

  .main-area {
    padding: 20px 16px;
  }

  .form-grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
