:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --border: #e3e7ee;
  --text: #1c2430;
  --muted: #6b7684;
  --primary: #2a7fd5;
  --primary-dark: #1f66ad;
  --danger: #d64545;
  --warning: #d98a1a;
  --success: #2f9e63;
  --sidebar: #1c2733;
  --sidebar-text: #c9d3de;
  --radius: 10px;
  --font: "Vazirmatn", "Segoe UI", Tahoma, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 600; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.05rem; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: .85em; }

.layout { display: flex; min-height: 100vh; }
.sidebar { width: 230px; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: .6rem; padding: 1.1rem 1.2rem; font-size: 1.15rem; font-weight: 700; color: #fff; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar nav { display: flex; flex-direction: column; padding: .6rem; gap: 2px; }
.sidebar nav a { color: var(--sidebar-text); padding: .55rem .9rem; border-radius: 8px; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar-footer { margin-top: auto; padding: .9rem 1rem; border-top: 1px solid rgba(255,255,255,.08); font-size: .85rem; }
.sidebar-footer select { width: 100%; margin-bottom: .6rem; background: #273444; color: #fff; border: 1px solid #3a4a5c; border-radius: 6px; padding: .3rem; }
.me { display: flex; justify-content: space-between; align-items: center; }
button.link { background: none; border: none; color: #8fb8e8; cursor: pointer; padding: 0; font: inherit; }

.content { flex: 1; padding: 1.4rem 1.8rem 3rem; max-width: 1400px; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.2rem; gap: 1rem; flex-wrap: wrap; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.3rem; margin-bottom: 1.2rem; }
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) { .grid.cols-4, .grid.cols-3 { grid-template-columns: repeat(2, 1fr); } .sidebar { width: 190px; } }
@media (max-width: 700px) { .layout { flex-direction: column; } .sidebar { width: 100%; height: auto; position: static; } .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } .content { padding: 1rem; } }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; }
.stat .label { color: var(--muted); font-size: .8rem; }
.stat .value { font-size: 1.6rem; font-weight: 700; }
.stat .sub { color: var(--muted); font-size: .8rem; }

table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { padding: .6rem .8rem; border-bottom: 1px solid var(--border); text-align: start; vertical-align: top; }
th { background: #f7f9fc; color: var(--muted); font-weight: 600; font-size: .8rem; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfd; }
td.num { white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.nowrap { white-space: nowrap; }
.truncate { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: #e9edf3; color: #3d4956; }
.badge.green { background: #dff5e8; color: #1f7a48; }
.badge.red { background: #fde3e3; color: #a12b2b; }
.badge.orange { background: #fdeed7; color: #9a5e07; }
.badge.blue { background: #ddebfb; color: #1c5ea0; }
.badge.gray { background: #e9edf3; color: #55606d; }

.btn { display: inline-block; padding: .45rem .95rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font: inherit; font-size: .9rem; }
.btn:hover { background: #f4f6f9; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { background: #b93a3a; }
.btn.warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn.sm { padding: .25rem .6rem; font-size: .8rem; }
form.inline { display: inline; }

.form-row { margin-bottom: .9rem; }
.form-row label { display: block; font-weight: 600; margin-bottom: .25rem; }
.form-row .help { color: var(--muted); font-size: .8rem; }
input[type=text], input[type=password], input[type=number], input[type=file], select, textarea {
  width: 100%; padding: .5rem .7rem; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff; color: var(--text);
}
input[type=checkbox] { width: 1rem; height: 1rem; vertical-align: middle; }
.check label { display: inline; font-weight: 500; margin-inline-start: .3rem; }
.errorlist { color: var(--danger); margin: .2rem 0 0; padding: 0; list-style: none; font-size: .85rem; }
.filters { display: flex; gap: .5rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.filters input[type=text] { width: 260px; }
.filters select { width: auto; }

.flashes { margin-bottom: 1rem; }
.flash { padding: .6rem 1rem; border-radius: 8px; margin-bottom: .4rem; border: 1px solid; }
.flash.success { background: #e6f7ee; border-color: #b8e5cb; color: #1f7a48; }
.flash.warning { background: #fff5e5; border-color: #f4d7a5; color: #9a5e07; }
.flash.error { background: #fdeaea; border-color: #f2bcbc; color: #a12b2b; }
.flash.info { background: #e8f1fc; border-color: #bcd6f3; color: #1c5ea0; }

.pagination { display: flex; gap: .4rem; align-items: center; margin-top: 1rem; }
.pagination a, .pagination span { padding: .3rem .7rem; border: 1px solid var(--border); border-radius: 6px; background: #fff; }

.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: #dbe3ec; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; color: #4b5b6e; vertical-align: middle; }
.avatar.lg { width: 72px; height: 72px; font-size: 1.6rem; }
.user-cell { display: flex; gap: .6rem; align-items: center; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 2rem; box-shadow: 0 10px 30px rgba(0,0,0,.06); }
.login-card h1 { text-align: center; margin-bottom: 1.4rem; }

/* message list */
.msg { display: flex; gap: .8rem; padding: .7rem 0; border-bottom: 1px solid var(--border); }
.msg:last-child { border-bottom: none; }
.msg .body { flex: 1; min-width: 0; }
.msg .meta { color: var(--muted); font-size: .78rem; display: flex; gap: .6rem; flex-wrap: wrap; }
.msg .text { white-space: pre-wrap; word-break: break-word; margin: .15rem 0; }
.msg.deleted { background: #fff8f8; }
.msg.deleted .text { color: #8a4a4a; }
.msg .thumb { max-width: 220px; max-height: 180px; border-radius: 8px; border: 1px solid var(--border); display: block; margin: .3rem 0; }
.msg .file { display: inline-flex; gap: .4rem; align-items: center; background: #f2f5f9; padding: .3rem .7rem; border-radius: 8px; margin: .3rem 0; }
.msg .reply { border-inline-start: 3px solid var(--primary); padding: .1rem .6rem; color: var(--muted); font-size: .8rem; margin: .2rem 0; }
.msg .tools { display: flex; gap: .3rem; align-items: flex-start; }
audio, video { max-width: 320px; display: block; margin: .3rem 0; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }
