/* MathBoard Server - hand written CSS. White cards on soft grey, accent #1f63e0, 44px touch targets. */
:root {
  --bg: #eef1f5; --card: #fff; --ink: #1b2330; --muted: #657084; --line: #e1e6ee;
  --accent: #1f63e0; --accent-dark: #164fb8; --accent-soft: #e8f0fe;
  --ok: #12805c; --ok-soft: #e4f6ee; --warn: #9a5b00; --warn-soft: #fff4dc; --err: #c2352b; --err-soft: #fdebe9;
  --radius: 14px; --shadow: 0 1px 2px rgba(20,30,50,.06), 0 4px 14px rgba(20,30,50,.06);
  --touch: 44px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 'Lexend', system-ui, -apple-system, 'Segoe UI', Roboto, Tahoma, 'Noto Sans Arabic', sans-serif;
}
body.modal-open { overflow: hidden; }
h1, h2 { margin: 0 0 .4em; line-height: 1.25; font-weight: 600; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; }
p { margin: 0 0 1em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }
code { background: #f1f3f7; padding: 1px 6px; border-radius: 6px; font-size: .92em; }
.muted { color: var(--muted); } .small { font-size: .82rem; } .text-center { text-align: center; }
.ic { width: 20px; height: 20px; flex: none; vertical-align: middle; }
.inline { display: inline; margin: 0; }

/* ---- Top bar ------------------------------------------------------- */
.topbar { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; padding-top: env(safe-area-inset-top); }
.topbar-in { max-width: 1180px; margin: 0 auto; padding: 8px 16px; display: flex; align-items: center; gap: 12px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink); font-size: 1.05rem; }
.brand .ic { color: var(--accent); width: 26px; height: 26px; }
.brand:hover { text-decoration: none; }
.topnav { margin-left: auto; display: flex; align-items: center; gap: 2px; flex-wrap: nowrap; justify-content: flex-end; min-width: 0; }
.topnav a, .linkbtn {
  display: inline-flex; align-items: center; gap: 6px; min-height: var(--touch); padding: 0 12px; border-radius: 10px;
  color: var(--ink); background: none; border: 0; font: inherit; cursor: pointer; max-width: 200px;
}
.topnav a span, .linkbtn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topnav a:hover, .linkbtn:hover { background: var(--bg); text-decoration: none; }
.pub-title { margin-left: 8px; display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.pub-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view-only { margin-left: auto; }

/* ---- Layout -------------------------------------------------------- */
.content { max-width: 1180px; margin: 0 auto; padding: 20px 16px 48px; }
.content.wide { max-width: 1180px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.count { font-size: .8rem; background: #fff; border: 1px solid var(--line); border-radius: 99px; padding: 1px 10px; color: var(--muted); vertical-align: middle; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.center-card { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px 14px; }
.center-card .card { width: 100%; }
.narrow { max-width: 420px; }
.form-card { max-width: 560px; }
.big-icon { width: 64px; height: 64px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; }
.big-icon .ic { width: 30px; height: 30px; } .big-icon.ok { background: var(--ok-soft); color: var(--ok); }
.login-logo { width: 56px; height: 56px; border-radius: 16px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; margin: 0 auto 10px; }
.login-logo .ic { width: 30px; height: 30px; }
.empty { text-align: center; padding: 48px 20px; }
.stack > * + * { margin-top: 16px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin: 0; } .kv dt { color: var(--muted); } .kv dd { margin: 0; }

/* ---- Forms & buttons ---------------------------------------------- */
.field { display: block; } .field > span { display: block; font-weight: 500; margin-bottom: 6px; font-size: .92rem; }
.input {
  width: 100%; min-height: var(--touch); padding: 8px 12px; border: 1.5px solid #d3dae6; border-radius: 10px; background: #fff;
  font: inherit; color: var(--ink); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31,99,224,.18); }
select.input { appearance: auto; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--touch); padding: 0 18px;
  border-radius: 10px; border: 1.5px solid #d3dae6; background: #fff; color: var(--ink); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
  touch-action: manipulation;
}
.btn:hover { background: #f6f8fb; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--err); border-color: #f0c4c0; } .btn.danger:hover { background: var(--err-soft); }
.modal .btn.danger { background: var(--err); border-color: var(--err); color: #fff; } .modal .btn.danger:hover { background: #a02a21; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: .88rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:focus-visible, .kebab:focus-visible, .item-link:focus-visible, .pick:focus-visible { outline: 3px solid rgba(31,99,224,.45); outline-offset: 2px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.switch { display: flex; align-items: center; gap: 12px; min-height: var(--touch); cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.slider { width: 46px; height: 26px; background: #c5cddb; border-radius: 99px; position: relative; transition: background .15s; flex: none; }
.slider::after { content: ''; position: absolute; width: 20px; height: 20px; background: #fff; border-radius: 50%; top: 3px; left: 3px; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + .slider { background: var(--ok); } .switch input:checked + .slider::after { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 3px solid rgba(31,99,224,.45); outline-offset: 2px; }
.searchbox { position: relative; } .searchbox .ic { position: absolute; left: 12px; top: 12px; color: var(--muted); } .searchbox .input { padding-left: 38px; width: 240px; }

.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; font-size: .92rem; background: var(--ok-soft); color: #0b5a40; }
.alert.err { background: var(--err-soft); color: #8c231b; } .alert.warn { background: var(--warn-soft); color: var(--warn); }
.checks { list-style: none; padding: 0; margin: 0 0 16px; font-size: .88rem; }
.checks li { display: flex; gap: 8px; align-items: center; padding: 3px 0; } .checks .ok { color: var(--ok); } .checks .bad { color: var(--err); }

/* ---- Badges --------------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .74rem; font-weight: 500; padding: 2px 9px; border-radius: 99px; background: #eef1f5; color: var(--muted); white-space: nowrap; }
.badge .ic { width: 13px; height: 13px; }
.badge.public { background: var(--ok-soft); color: var(--ok); } .badge.private { background: #eef1f5; color: var(--muted); }
.badge.type { background: var(--accent-soft); color: var(--accent); } .badge.view-only { background: var(--warn-soft); color: var(--warn); font-size: .8rem; padding: 4px 12px; }

/* ---- Breadcrumbs ---------------------------------------------------- */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 1.05rem; font-weight: 500; margin-bottom: 16px; }
.page-head .crumbs { margin: 0; }
.crumbs .sep { color: #aab3c2; } .crumbs > span:last-child { font-weight: 600; }

/* ---- Item grid ------------------------------------------------------ */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; align-items: start; }
.item { position: relative; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: visible; transition: transform .12s, box-shadow .12s; display: block; color: inherit; }
.item:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(20,30,50,.07), 0 10px 24px rgba(20,30,50,.1); text-decoration: none; }
.item-link { display: block; color: inherit; border-radius: var(--radius); } .item-link:hover { text-decoration: none; }
.item-thumb { aspect-ratio: 16 / 10; background: #f4f6fa; border-radius: var(--radius) var(--radius) 0 0; display: flex; align-items: center; justify-content: center; color: #a3b0c6; overflow: hidden; }
.item-thumb .ic { width: 44px; height: 44px; stroke-width: 1.4; } .item.folder .item-thumb { background: var(--accent-soft); color: var(--accent); aspect-ratio: 16 / 7; }
.item-thumb img { width: 100%; height: 100%; object-fit: cover; background: #fff; }
.item-body { padding: 12px 14px 14px; }
.item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { display: flex; justify-content: space-between; align-items: center; gap: 4px 8px; margin-top: 6px; flex-wrap: wrap; }
.kebab {
  position: absolute; right: 6px; top: 6px; width: var(--touch); height: var(--touch); border-radius: 12px; border: 0; background: rgba(255,255,255,.92); color: var(--ink); cursor: pointer;
  display: flex; align-items: center; justify-content: center; z-index: 2; box-shadow: 0 1px 4px rgba(20,30,50,.18);
}
.kebab:hover { background: #fff; color: var(--accent); }
.card-menu { position: absolute; right: 6px; top: 54px; min-width: 190px; background: #fff; border-radius: 12px; box-shadow: 0 8px 30px rgba(20,30,50,.22); padding: 6px; z-index: 30; border: 1px solid var(--line); }
.card-menu button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: var(--touch); padding: 0 12px; border: 0; background: none; border-radius: 8px; font: inherit; color: var(--ink); cursor: pointer; text-align: left; }
.card-menu button:hover, .card-menu button:focus-visible { background: var(--bg); outline: none; } .card-menu button.danger { color: var(--err); }

/* ---- Table ---------------------------------------------------------- */
.table-card { padding: 6px 10px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 500; padding: 12px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; } .table .num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { white-space: nowrap; text-align: right; }

/* ---- Modal / toast -------------------------------------------------- */
.overlay { position: fixed; inset: 0; background: rgba(20,28,45,.5); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100; animation: fade .12s; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 480px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px 6px; }
.modal-head h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: var(--touch); height: var(--touch); border: 0; background: none; border-radius: 10px; cursor: pointer; color: var(--muted); display: flex; align-items: center; justify-content: center; flex: none; }
.icon-btn:hover { background: var(--bg); }
.modal-body { padding: 8px 18px 14px; overflow: auto; } .modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 18px 18px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #1b2330; color: #fff; padding: 12px 18px; border-radius: 12px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 200; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); } #toast.err { background: var(--err); }

/* Share dialog + move picker */
.radio { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 12px; cursor: pointer; min-height: var(--touch); }
.radio input { margin-top: 5px; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.radio:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.share-status { padding: 10px 12px; border-radius: 10px; font-size: .9rem; } .share-status.public { background: var(--ok-soft); color: #0b5a40; } .share-status.private { background: #eef1f5; color: var(--muted); }
.share-link { display: flex; gap: 8px; } .share-link:empty { display: none; }
.picker { border: 1.5px solid var(--line); border-radius: 12px; max-height: 50vh; overflow: auto; padding: 4px; }
.pick { display: flex; align-items: center; gap: 8px; width: 100%; min-height: var(--touch); border: 0; background: none; border-radius: 8px; font: inherit; color: var(--ink); cursor: pointer; text-align: left; }
.pick:hover { background: var(--bg); } .pick.sel { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---- Phones ----------------------------------------------------------- */
@media (max-width: 720px) {
  .content { padding: 14px 12px 40px; }
  .topnav a span { display: none; } .topnav .linkbtn span { display: none; } .topnav a[href$="account.php"] span { display: inline; max-width: 80px; }
  .topbar-in { padding: 6px 10px; gap: 6px; } .brand span { font-size: .98rem; }
  .topnav a, .linkbtn { padding: 0 10px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .page-head .actions { width: 100%; } .page-head .actions .btn { flex: 1; }
  .searchbox { flex: 1 1 100%; } .searchbox .input { width: 100%; }
  .kv { grid-template-columns: 90px 1fr; }
  .table.responsive thead { display: none; }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr { padding: 12px 6px; border-bottom: 1px solid var(--line); } .table.responsive tr:last-child { border-bottom: 0; }
  .table.responsive td { border: 0; padding: 3px 6px; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; text-align: left; flex: none; }
  .table.responsive td.row-actions { justify-content: flex-end; padding-top: 10px; } .table.responsive td.row-actions::before { display: none; }
  .pub-title span.muted { display: none; }
  .modal { max-width: none; } .overlay { align-items: flex-end; padding: 0; } .modal { border-radius: 18px 18px 0 0; max-height: 92vh; }
  .modal-foot .btn { flex: 1; }
}
@media (max-width: 380px) { .grid { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
