/* ===== Saktitham Law Office — back office ===== */
:root {
  --navy: #0b1f3a;
  --navy-2: #12305a;
  --gold: #c9a24b;
  --gold-soft: #f6efdc;
  --ink: #1d2433;
  --muted: #6b7486;
  --line: #e5e8ef;
  --bg: #f4f6fa;
  --danger: #c0392b;
  --ok: #1e8a52;
  --radius: 12px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Sarabun', system-ui, sans-serif; font-size: 15px; color: var(--ink); background: var(--bg); line-height: 1.6; }
a { color: var(--navy-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .6em; line-height: 1.3; }
.icon { flex-shrink: 0; }
.muted { color: var(--muted); font-size: .9em; }
.small { font-size: .8rem; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 32px 0; margin: 0; }

/* ----- Layout ----- */
.sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; background: var(--navy); color: #c9d2e3; overflow-y: auto; z-index: 40; transition: transform .2s; }
.sidebar__brand { display: flex; align-items: center; gap: 10px; padding: 20px; border-bottom: 1px solid rgba(255,255,255,.08); color: #fff; }
.sidebar__brand:hover { text-decoration: none; }
.sidebar__brand img { border-radius: 50%; }
.sidebar__brand span { display: flex; flex-direction: column; line-height: 1.2; }
.sidebar__brand strong { color: #ead39a; }
.sidebar__brand small { color: #8e9ab2; font-size: .75rem; letter-spacing: .1em; }
.sidebar__nav { display: flex; flex-direction: column; padding: 12px 10px 24px; }
.sidebar__nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: #c9d2e3; }
.sidebar__nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.sidebar__nav a.is-active { background: rgba(201,162,75,.16); color: #ead39a; }
.sidebar__label { margin: 18px 12px 6px; font-size: .72rem; text-transform: uppercase; letter-spacing: .12em; color: #6f7c96; }

.main { margin-left: 250px; min-height: 100vh; }
.topnav { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 16px; height: 64px; padding: 0 28px; background: #fff; border-bottom: 1px solid var(--line); }
.topnav__title { font-size: 1.2rem; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topnav__toggle { display: none; background: none; border: 0; cursor: pointer; color: var(--navy); padding: 4px; }
.topnav__right { display: flex; align-items: center; gap: 6px; }
.topnav__right form { margin: 0; }
.topnav__link { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 8px; color: var(--ink); background: none; border: 0; font: inherit; cursor: pointer; }
.topnav__link:hover { background: var(--bg); text-decoration: none; }
.content { padding: 28px; max-width: 1280px; }
.backdrop { display: none; }

/* ----- Components ----- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--bg); text-decoration: none; }
.btn--primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn--primary:hover { background: var(--navy-2); }
.btn--danger { color: var(--danger); border-color: #f0c8c3; }
.btn--danger:hover { background: #fdecec; }
.btn--link { border-color: transparent; color: var(--navy-2); }
.btn--sm { padding: 4px 10px; font-size: .88rem; }
.btn--block { width: 100%; }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
.alert--success { background: #e8f6ee; color: #1e6b41; border: 1px solid #b9e2c9; }
.alert--error { background: #fdecec; color: #9b2c2c; border: 1px solid #f3c1c1; }
.alert--warn { background: #fdf3dc; color: #7a5a12; border: 1px solid #f0d99a; }
.alert--warn a { font-weight: 700; text-decoration: underline; }

.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 20px; }
.panel__head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.panel__head h2, .panel__title { font-size: 1.05rem; }
.panel__title { margin-top: 4px; padding-bottom: 10px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.kpi { display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; color: var(--ink); }
.kpi:hover { text-decoration: none; border-color: var(--gold); }
.kpi span { color: var(--muted); font-size: .9rem; }
.kpi strong { font-size: 1.9rem; line-height: 1.3; color: var(--navy); }
.kpi small { color: var(--muted); }
.kpi--accent { background: var(--navy); border-color: var(--navy); }
.kpi--accent span, .kpi--accent small { color: #aeb9cf; }
.kpi--accent strong { color: #ead39a; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.grid-2--wide { grid-template-columns: 1.4fr 1fr; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.search { display: flex; gap: 8px; flex-wrap: wrap; }
.search input, .search select { padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff; min-width: 220px; }
.search select { min-width: 0; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 600; font-size: .85rem; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.is-unread td { background: #fffaf0; }
.table tr.is-unread .strong::before { content: '● '; color: var(--gold); }
.table form { margin: 0; display: inline; }
.actions { text-align: right; white-space: nowrap; }
.actions-col { width: 1%; }
.w-thumb { width: 64px; }
.thumb { width: 56px; height: 40px; object-fit: cover; border-radius: 6px; display: block; }
.thumb--empty { background: var(--bg); }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--bg); color: var(--muted); border: 0; font-family: inherit; cursor: default; }
button.badge { cursor: pointer; }
.badge--on { background: #e3f4ea; color: var(--ok); }
.badge--off { background: #eef0f4; color: var(--muted); }
.badge--new { background: var(--gold-soft); color: #8a6516; }
.badge--in_progress { background: #e5eefc; color: #1f4f9c; }
.badge--closed { background: #eef0f4; color: var(--muted); }

.pager { display: flex; gap: 6px; flex-wrap: wrap; }
.pager a { min-width: 36px; height: 36px; display: grid; place-items: center; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.pager a.is-active { background: var(--navy); color: #fff; border-color: var(--navy); }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }

/* ----- Forms ----- */
.form--narrow { max-width: 640px; }
.field { margin-bottom: 18px; }
.field > label { display: block; font-weight: 600; margin-bottom: 6px; }
.field em { color: var(--danger); font-style: normal; }
.field input:not([type=checkbox]):not([type=file]), .field select, .field textarea { width: 100%; padding: 9px 12px; border: 1px solid #cfd5e1; border-radius: 8px; font: inherit; background: #fff; color: var(--ink); }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,162,75,.2); }
.field input:disabled { background: var(--bg); }
.field textarea { resize: vertical; }
.field--check label { display: inline-flex; gap: 8px; align-items: center; font-weight: 500; cursor: pointer; }
.field--full { grid-column: 1 / -1; }
.fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.hint { display: block; color: var(--muted); font-size: .85rem; margin-top: 4px; }
.inline { display: inline-flex; gap: 6px; align-items: center; margin: 8px 0; font-weight: 400; }
.image-field__preview { max-width: 280px; max-height: 180px; border-radius: 8px; border: 1px solid var(--line); display: block; margin-bottom: 6px; }
.form__actions { display: flex; gap: 10px; flex-wrap: wrap; padding-top: 6px; }
.form__actions--sticky { position: sticky; bottom: 0; background: var(--bg); padding: 14px 0; }

.details { display: grid; grid-template-columns: 110px 1fr; gap: 8px 16px; margin: 0 0 20px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.message-body { white-space: pre-wrap; background: var(--bg); padding: 16px; border-radius: 10px; }
.danger-zone { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); }

/* ----- Editor (WordPress-style two columns) ----- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.editor__side { position: sticky; top: 84px; display: flex; flex-direction: column; }
.field--big input { font-size: 1.35rem !important; font-weight: 600; padding: 12px 14px !important; }
.permalink { margin: -6px 0 0; color: var(--muted); font-size: .88rem; word-break: break-all; }
.permalink strong { color: var(--navy-2); }
.publish-box__actions { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.image-field__preview[hidden] { display: none; }
.image-field__preview { width: 100%; max-width: none; max-height: 220px; object-fit: cover; }
.image-field__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tox-tinymce { border-radius: 8px !important; border-color: #cfd5e1 !important; }

/* ----- SEO panel ----- */
.serp { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 18px; font-family: Arial, sans-serif; background: #fff; max-width: 640px; }
.serp__site { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.serp__site img { width: 26px; height: 26px; border-radius: 50%; }
.serp__site span { display: flex; flex-direction: column; line-height: 1.25; font-size: .82rem; color: #202124; }
.serp__site small { color: #4d5156; word-break: break-all; }
.serp__title { color: #1a0dab; font-size: 1.2rem; line-height: 1.35; margin: 4px 0; }
.serp__desc { color: #4d5156; font-size: .9rem; line-height: 1.5; }
.counter { display: block; font-size: .8rem; margin-top: 2px; color: var(--muted); }
.counter--ok { color: var(--ok); }
.counter--warn { color: #b7791f; }
.seo-checks__title { font-size: .98rem; display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.seo-checks { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.seo-check { position: relative; padding-left: 22px; font-size: .92rem; }
.seo-check::before { content: ''; position: absolute; left: 2px; top: .5em; width: 11px; height: 11px; border-radius: 50%; }
.seo-check--ok::before { background: #2fa36b; }
.seo-check--warn::before { background: #e3a008; }
.seo-check--bad::before { background: #d64545; }
.seo-score { font-size: .8rem; padding: 2px 10px; border-radius: 999px; font-weight: 600; }
.seo-score--ok { background: #e3f4ea; color: var(--ok); }
.seo-score--warn { background: #fdf3dc; color: #8a6516; }
.seo-score--bad { background: #fdecec; color: var(--danger); }

.badge--scheduled { background: #e5eefc; color: #1f4f9c; }
.sidebar__cta { margin: 4px 2px 8px; justify-content: center; background: linear-gradient(135deg, #ead39a, #c9a24b); color: #071528 !important; font-weight: 600; }
.sidebar__cta:hover { filter: brightness(1.05); }

/* ----- Media library ----- */
.upload-drop { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 28px 16px; border: 2px dashed #cfd5e1; border-radius: 12px; text-align: center; color: var(--navy); transition: background .15s, border-color .15s; }
.upload-drop.is-over { background: var(--gold-soft); border-color: var(--gold); }
.upload-drop p { margin: 6px 0 0; }
.upload-drop .link { color: var(--navy-2); text-decoration: underline; cursor: pointer; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 20px; }
.media-card { min-width: 0; background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.media-card__img { display: block; aspect-ratio: 4 / 3; background: var(--bg); }
.media-card__img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-card__body { padding: 10px 12px 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.media-card__name { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-card .used { color: var(--ok); font-weight: 600; }
.media-card__alt { display: flex; gap: 6px; }
.media-card__alt input { flex: 1; min-width: 0; padding: 6px 8px; border: 1px solid #cfd5e1; border-radius: 6px; font: inherit; font-size: .85rem; }
.media-card__actions { display: flex; justify-content: space-between; gap: 6px; }
.media-card__actions form { margin: 0; }

/* ----- Library with folders ----- */
.library { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 20px; align-items: start; }
.library__folders { position: sticky; top: 84px; }
.folder-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.folder-list a { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; color: var(--ink); }
.folder-list a:hover { background: var(--bg); text-decoration: none; }
.folder-list a.is-active { background: var(--navy); color: #fff; }
.folder-list a span { margin-left: auto; font-size: .8rem; color: var(--muted); }
.folder-list a.is-active span { color: #ead39a; }
.folder-new, .folder-manage form { display: flex; gap: 6px; margin-bottom: 8px; }
.folder-new input, .folder-manage input { flex: 1; min-width: 0; padding: 6px 8px; border: 1px solid #cfd5e1; border-radius: 6px; font: inherit; font-size: .88rem; }
.folder-manage summary { cursor: pointer; font-size: .88rem; color: var(--navy-2); margin: 6px 0 10px; }
.bulk-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 16px; }
.bulk-bar select { padding: 5px 8px; border: 1px solid #cfd5e1; border-radius: 6px; font: inherit; font-size: .88rem; }
.bulk-bar .inline { margin: 0; }
.media-card { position: relative; }
.media-card.is-selected { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.media-card__select { position: absolute; top: 8px; left: 8px; z-index: 2; width: 28px; height: 28px; display: grid; place-items: center; background: rgba(255,255,255,.92); border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.2); cursor: pointer; }
.media-card__select input { width: 17px; height: 17px; cursor: pointer; }
.modal__tools select { padding: 8px; border: 1px solid #cfd5e1; border-radius: 8px; font: inherit; max-width: 40%; }

/* ----- Modal (media picker) ----- */
.modal { position: fixed; inset: 0; z-index: 1300; background: rgba(7, 21, 40, .6); display: grid; place-items: center; padding: 16px; }
.modal__box { width: min(880px, 100%); max-height: 88vh; display: flex; flex-direction: column; gap: 12px; background: #fff; border-radius: 14px; padding: 18px; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.modal__head { display: flex; justify-content: space-between; align-items: center; }
.modal__tools { display: flex; gap: 8px; }
.modal__tools input { flex: 1; min-width: 0; padding: 8px 12px; border: 1px solid #cfd5e1; border-radius: 8px; font: inherit; }
.modal__grid { overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; min-height: 160px; }
.modal__item { padding: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; cursor: pointer; aspect-ratio: 1; background: var(--bg); }
.modal__item:hover, .modal__item:focus { border-color: var(--gold); }
.modal__item img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ----- Login ----- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(ellipse at top, #1b4078, var(--navy) 60%); }
.login__box { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; padding: 36px 32px; text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.login__box img { margin: 0 auto 14px; border-radius: 50%; }
.login__box h1 { font-size: 1.3rem; margin-bottom: 2px; }
.login__box p { color: var(--muted); margin: 0 0 22px; }
.login__box .field { text-align: left; display: block; margin-bottom: 16px; font-weight: 600; }
.login__box .field input { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; border: 1px solid #cfd5e1; border-radius: 8px; font: inherit; }
.login__box .alert { text-align: left; }
.login__back { display: inline-block; margin-top: 10px; color: var(--muted); }
.login__help { font-size: .85rem; margin: 14px 0 0 !important; }

/* ----- Responsive ----- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .editor { grid-template-columns: 1fr; }
  .library { grid-template-columns: 1fr; }
  .library__folders { position: static; }
  .editor__side { position: static; }
  .grid-2, .grid-2--wide { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
  .main { margin-left: 0; }
  .topnav { padding: 0 16px; }
  .topnav__toggle { display: block; }
  .topnav__link span { display: none; }
  .content { padding: 16px; }
  .fields-2 { grid-template-columns: 1fr; }
  .search input { min-width: 0; flex: 1; }
}
@media (max-width: 700px) {
  /* Inputs at 16px stop iOS from zooming in on focus. */
  .field input:not([type=checkbox]):not([type=file]), .field select, .field textarea, .search input, .search select, .login__box .field input { font-size: 16px; }
  .topnav { height: 56px; gap: 10px; }
  .topnav__title { font-size: 1.05rem; }
  .topnav__right { gap: 0; }
  .panel { padding: 16px; border-radius: 10px; }
  .toolbar { align-items: stretch; }
  .toolbar > .btn { flex: 1; }
  .search { width: 100%; }
  .search input { flex: 1 1 140px; min-width: 0; }
  .search select { flex: 1 1 100%; }
  .details { grid-template-columns: 90px 1fr; }
  .form__actions .btn { flex: 1; }
  .media-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .media-card__alt { flex-direction: column; }
  .media-card__actions { flex-direction: column; }
  .media-card__actions .btn { width: 100%; }
  .modal__grid { grid-template-columns: repeat(3, 1fr); }
  .modal__tools { flex-wrap: wrap; }
  .modal__tools select { max-width: none; flex: 1 1 100%; }
  .folder-list { flex-direction: row; flex-wrap: wrap; }
  .folder-list a { border: 1px solid var(--line); padding: 6px 10px; }
  .serp__title { font-size: 1.05rem; }

  /* Tables become stacked cards: one row per card, labels from data-label. */
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { position: relative; padding: 12px 14px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 10px; }
  .table tr:last-child { margin-bottom: 0; }
  .table td, .table tr:last-child td { padding: 3px 0; border: 0; white-space: normal; }
  .table td[data-label] { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: right; }
  .table td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .85rem; text-align: left; flex-shrink: 0; }
  .table td.cell-title { font-size: 1.02rem; padding-bottom: 6px; }
  .table td.cell-thumb { float: right; width: auto; margin-left: 10px; }
  .table td.cell-thumb:has(.thumb--empty) { display: none; }
  .table td.actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 10px; margin-top: 6px; border-top: 1px solid var(--line); }
  .table td.actions:empty { display: none; }
  .table tr.is-unread td { background: none; }
  .table tr.is-unread { background: #fffaf0; }
}

@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 14px; }
  .kpi strong { font-size: 1.5rem; }
}
