/* IG Manager: clean modern dashboard. Light + automatic dark mode. Inter, soft borders, layered shadows, indigo accent. */
:root {
  color-scheme: light dark;
  --bg: #F5F6FA;
  --surface: #FFFFFF;
  --surface-2: #F9FAFC;
  --line: #E5E7EF;
  --line-strong: #D3D6E3;
  --text: #0F172A;
  --muted: #64748B;
  --accent: #4F46E5;
  --accent-hover: #4338CA;
  --accent-soft: #EEF0FF;
  --on-accent: #FFFFFF;
  --ok: #047857;      --ok-bg: #DCFCE7;
  --warn: #92400E;    --warn-bg: #FEF3C7;
  --err: #B91C1C;     --err-bg: #FEE2E2;
  --info: #1D4ED8;    --info-bg: #DBEAFE;
  --busy: #6D28D9;    --busy-bg: #EDE9FE;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .06);
  --shadow-lg: 0 10px 40px rgba(15, 23, 42, .18);
  --r: 14px;
  --r-sm: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0B0E17;
    --surface: #131827;
    --surface-2: #171D2E;
    --line: #232A3F;
    --line-strong: #323B55;
    --text: #E8ECF6;
    --muted: #8D98B3;
    --accent: #8B93FF;
    --accent-hover: #A3AAFF;
    --accent-soft: #1D2347;
    --on-accent: #0B0E17;
    --ok: #4ADE80;   --ok-bg: #0F2F20;
    --warn: #FBBF24; --warn-bg: #36280A;
    --err: #FCA5A5;  --err-bg: #3A1417;
    --info: #93C5FD; --info-bg: #14264A;
    --busy: #C4B5FD; --busy-bg: #2A1F55;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, .6);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; letter-spacing: -.02em; font-weight: 700; }
h1 { font-size: clamp(1.5rem, 3.4vw, 1.9rem); }
h2 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: .84rem; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }
.shell > div, .main { min-width: 0; }
.side {
  position: sticky; top: 0; height: 100vh; overflow: auto;
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 22px 14px; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; color: var(--text); padding: 0 8px; margin-bottom: 18px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent); font-weight: 800; font-size: .85rem; letter-spacing: .02em;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 40%, transparent);
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 11px; color: var(--muted); font-weight: 500;
  padding: 9px 12px; border-radius: var(--r-sm); transition: background .15s, color .15s;
}
.nav a svg { width: 19px; height: 19px; flex: none; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .count { margin-left: auto; font-size: .72rem; font-weight: 600; background: var(--accent); color: var(--on-accent); border-radius: 99px; padding: 1px 8px; }
.side-foot { margin-top: auto; padding: 14px 8px 0; border-top: 1px solid var(--line); }
.main { padding: 32px clamp(18px, 4vw, 48px) 64px; max-width: 1200px; width: 100%; }
.topbar { display: none; }

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 22px; }
.card + .card { margin-top: 18px; }
.grid > .card + .card, .list > .card + .card { margin-top: 0; }
.grid + .card, .card + .grid, .grid + .grid { margin-top: 18px; }
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.between { justify-content: space-between; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--text); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); padding: 9px 16px; min-height: 42px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .06); transition: background .15s, border-color .15s, transform .1s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); text-decoration: none; }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ok { background: var(--ok-bg); border-color: transparent; color: var(--ok); }
.btn-ok:hover { background: color-mix(in srgb, var(--ok-bg) 80%, var(--ok)); border-color: transparent; }
.btn-danger { background: var(--err-bg); border-color: transparent; color: var(--err); }
.btn-danger:hover { background: color-mix(in srgb, var(--err-bg) 80%, var(--err)); border-color: transparent; }
.btn[disabled] { opacity: .5; cursor: not-allowed; box-shadow: none; }

label { display: block; font-weight: 600; font-size: .9rem; margin: 0 0 6px; }
input[type=text], input[type=password], input[type=datetime-local], input[type=number], input[type=file], textarea, select {
  width: 100%; max-width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); padding: 10px 13px; min-height: 42px;
  transition: border-color .15s, box-shadow .15s;
}
input:hover, textarea:hover, select:hover { border-color: var(--muted); }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); outline: none; }
input[disabled], textarea[disabled] { background: var(--surface-2); color: var(--muted); }
input[type=file] { padding: 8px 10px; }
textarea { min-height: 220px; resize: vertical; line-height: 1.55; }
.field { margin-bottom: 18px; }
.hint { font-size: .82rem; color: var(--muted); margin-top: 6px; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 500; }
.check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }

.badge {
  display: inline-flex; align-items: center; font-size: .74rem; font-weight: 600; line-height: 1;
  border-radius: 99px; padding: 5px 10px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap;
}
.st-draft { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.st-sched { background: var(--info-bg); color: var(--info); border-color: transparent; }
.st-posting { background: var(--busy-bg); color: var(--busy); border-color: transparent; }
.st-posted { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.st-failed { background: var(--err-bg); color: var(--err); border-color: transparent; }
.type-tag { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.alert { border-radius: var(--r-sm); padding: 12px 16px; margin-bottom: 18px; font-weight: 500; border: 1px solid transparent; }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-err { background: var(--err-bg); color: var(--err); }
.alert-warn { background: var(--warn-bg); color: var(--warn); }
.alert ul { margin: 6px 0 0; padding-left: 20px; font-weight: 500; }
.alert a { color: inherit; text-decoration: underline; }

.stat .n { font-size: 2.3rem; font-weight: 700; line-height: 1; letter-spacing: -.03em; }
.stat .l { color: var(--muted); font-weight: 500; margin-top: 6px; }
a.stat-link { color: inherit; display: block; }
a.stat-link:hover { text-decoration: none; }
a.stat-link .card { transition: transform .15s, box-shadow .15s, border-color .15s; }
a.stat-link:hover .card { transform: translateY(-2px); border-color: var(--line-strong); box-shadow: var(--shadow-lg); }

.list { display: grid; gap: 12px; }
.item-card { padding: 0; transition: border-color .15s, box-shadow .15s; }
.item-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-lg); }
.actions { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 14px; border-top: 1px solid var(--line); }
.btn-sm { min-height: 34px; padding: 5px 14px; font-size: .84rem; }
.alert-info { background: var(--info-bg); color: var(--info); font-size: .88rem; }
.item { display: grid; grid-template-columns: 84px 1fr auto; gap: 18px; align-items: center; color: inherit; padding: 14px; transition: transform .15s, box-shadow .15s, border-color .15s; }
.card + .card.item, .list .card + .card { margin-top: 0; }
a.item:hover { text-decoration: none; }
.thumb { width: 84px; height: 112px; border-radius: 10px; object-fit: cover; background: var(--surface-2); display: block; border: 1px solid var(--line); }
.thumb-ph { display: grid; place-items: center; font-weight: 600; font-size: .8rem; color: var(--muted); }
.item h3 { margin: 0 0 4px; font-size: 1rem; overflow-wrap: anywhere; }
.item .cap { color: var(--muted); font-size: .88rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item .meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.item .right { text-align: right; font-weight: 500; font-size: .85rem; color: var(--text); }

.day { font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 28px 0 10px; }
.day:first-child { margin-top: 0; }

.preview { display: flex; gap: 10px; flex-wrap: wrap; }
.preview video { width: min(100%, 300px); aspect-ratio: 9 / 16; background: #000; border-radius: var(--r); box-shadow: var(--shadow); }
.preview img { width: 120px; height: 150px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: .86rem; vertical-align: top; }
th { background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
.logbox { max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: var(--r-sm); }

.counter { font-weight: 500; font-size: .82rem; color: var(--muted); margin-top: 6px; }
.counter.over { color: var(--err); }

dialog { border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-lg); padding: 24px; max-width: min(92vw, 420px); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(8, 11, 20, .55); backdrop-filter: blur(3px); }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(900px 500px at 15% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.login-card { width: min(100%, 410px); padding: 30px; }
.login-card .brand { padding: 0; }
.empty { text-align: center; padding: 44px 14px; color: var(--muted); font-weight: 500; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .topbar { display: block; position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); padding: 10px 12px 8px; }
  .topbar .brand { margin: 0 0 8px; padding: 0 4px; }
  .topbar .nav { flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .topbar .nav::-webkit-scrollbar { display: none; }
  .topbar .nav a { white-space: nowrap; padding: 7px 12px; font-size: .88rem; border-radius: 99px; }
  .topbar .nav a svg { display: none; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .main { padding-top: 22px; }
}
@media (max-width: 620px) {
  .g2, .g3 { grid-template-columns: 1fr; }
  .item { grid-template-columns: 68px 1fr; gap: 14px; }
  .thumb { width: 68px; height: 92px; }
  .item .right { grid-column: 1 / -1; text-align: left; }
  .card { padding: 18px; }
  .card.item-card { padding: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
