@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@300;400;500;600;700&family=IBM+Plex+Sans:wght@300;400;500;600;700&display=swap');

/* ══════════════ THEMES ══════════════ */
:root[data-theme="dark"] {
  --bg:        #0d0f14;
  --bg2:       #13161d;
  --bg3:       #191d27;
  --bg4:       #1f2434;
  --border:    #252b3b;
  --border2:   #2e3650;
  --accent:    #c8a96a;
  --accent2:   #e8c990;
  --accentbg:  rgba(200,169,106,0.12);
  --text1:     #e8eaf2;
  --text2:     #8b91ab;
  --text3:     #4d5470;
  --success:   #3db87a;
  --warn:      #e89e3a;
  --danger:    #e05050;
  --info:      #5b8dee;
  --shadow:    0 4px 30px rgba(0,0,0,0.5);
  --shadow2:   0 8px 60px rgba(0,0,0,0.7);
  --glass:     rgba(25,29,39,0.85);
}

:root[data-theme="light"] {
  --bg:        #f0f2f7;
  --bg2:       #ffffff;
  --bg3:       #f8f9fc;
  --bg4:       #eef0f6;
  --border:    #e0e4ef;
  --border2:   #cdd2e4;
  --accent:    #8b6914;
  --accent2:   #a07c20;
  --accentbg:  rgba(139,105,20,0.08);
  --text1:     #1a1e30;
  --text2:     #5a6280;
  --text3:     #9ba3be;
  --success:   #1e9e5c;
  --warn:      #c07010;
  --danger:    #cc3030;
  --info:      #3060c8;
  --shadow:    0 2px 20px rgba(0,0,0,0.08);
  --shadow2:   0 8px 40px rgba(0,0,0,0.15);
  --glass:     rgba(255,255,255,0.92);
}

/* ══════════════ BASE ══════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }

body {
  font-family: 'IBM Plex Sans Arabic', 'IBM Plex Sans', sans-serif;
  background: var(--bg);
  color: var(--text1);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}

[dir="rtl"] { direction: rtl; text-align: right; }
[dir="ltr"] { direction: ltr; text-align: left; }

/* ══════════════ SIDEBAR ══════════════ */
:root { --sw: 250px; --topbar-h: 58px; }

.sidebar {
  position: fixed; top: 0; bottom: 0;
  width: var(--sw);
  background: var(--bg2);
  border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 200;
  transition: transform 0.3s ease;
}

[dir="rtl"] .sidebar { right: 0; left: auto; }
[dir="ltr"] .sidebar { left: 0; right: auto; }

.sidebar-logo {
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}

.logo-icon {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; flex-shrink: 0;
}

.logo-text { flex: 1; }
.logo-name { font-size: 1.1rem; font-weight: 700; color: var(--text1); }
.logo-sub  { font-size: 0.68rem; color: var(--text3); margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }

.nav-section {
  font-size: 0.65rem; font-weight: 600; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--text3);
  padding: 10px 10px 4px; margin-top: 4px;
}

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 9px;
  color: var(--text2); text-decoration: none;
  font-size: 0.85rem; font-weight: 500;
  transition: all 0.15s ease; margin-bottom: 1px;
  position: relative;
}

.nav-link:hover { background: var(--bg4); color: var(--text1); }
.nav-link.active { background: var(--accentbg); color: var(--accent); font-weight: 600; }

.nav-link.active::before {
  content: '';
  position: absolute; inset-inline-start: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 18px; background: var(--accent); border-radius: 2px;
}

.nav-icon { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.75; }
.nav-link.active .nav-icon { opacity: 1; }

.nav-badge {
  margin-inline-start: auto;
  background: var(--danger); color: #fff;
  font-size: 0.65rem; font-weight: 700;
  padding: 1px 6px; border-radius: 10px;
}

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
}

.user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 9px;
  background: var(--bg4); cursor: pointer;
  transition: background 0.15s;
}
.user-card:hover { background: var(--bg3); }

.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 700; color: var(--bg);
  flex-shrink: 0;
}

.avatar-lg { width: 64px; height: 64px; font-size: 1.5rem; border-radius: 50%; }

.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 0.82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.7rem; color: var(--text3); margin-top: 1px; }

/* ══════════════ MAIN LAYOUT ══════════════ */
.main {
  min-height: 100vh;
  display: flex; flex-direction: column;
}

[dir="rtl"] .main { margin-right: var(--sw); margin-left: 0; }
[dir="ltr"] .main { margin-left: var(--sw); margin-right: 0; }

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
}

.page-title { font-size: 1.1rem; font-weight: 700; color: var(--text1); }

.topbar-right { display: flex; align-items: center; gap: 8px; }

/* ── Content ── */
.content { flex: 1; padding: 24px; }

/* ══════════════ CARDS ══════════════ */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  transition: border-color 0.2s;
}
.card:hover { border-color: var(--border2); }

.card-title {
  font-size: 0.92rem; font-weight: 700; color: var(--text1);
  margin-bottom: 16px; display: flex; align-items: center; gap: 8px;
}

/* ── Stat Cards ── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }


.stat-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px 18px;
  display: flex; align-items: center; gap: 12px;
  transition: all 0.2s; position: relative; overflow: hidden;
  min-width: 0;
}

.stat-card::after {
  content: '';
  position: absolute; top: 0; inset-inline-start: 0;
  width: 100%; height: 2px;
  background: var(--accent); opacity: 0;
  transition: opacity 0.2s;
}
.stat-card:hover::after { opacity: 1; }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.stat-icon {
  width: 44px; height: 44px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.si-gold  { background: rgba(200,169,106,0.12); color: var(--accent); }
.si-blue  { background: rgba(91,141,238,0.12); color: var(--info); }
.si-green { background: rgba(61,184,122,0.12); color: var(--success); }
.si-red   { background: rgba(224,80,80,0.12);  color: var(--danger); }
.si-purple{ background: rgba(150,80,224,0.12); color: #9650e0; }

.stat-val   { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.75rem; color: var(--text3); margin-top: 3px; text-transform: uppercase; letter-spacing: 0.5px; }

/* ══════════════ TABLE ══════════════ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  padding: 9px 14px; text-align: inherit;
  font-size: 0.7rem; font-weight: 600; color: var(--text3);
  text-transform: uppercase; letter-spacing: 1px;
  border-bottom: 1px solid var(--border);
}
td { padding: 12px 14px; font-size: 0.84rem; color: var(--text2); border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s; }
tbody tr:hover td { background: var(--bg4); color: var(--text1); }

/* ══════════════ BUTTONS ══════════════ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 9px;
  font-family: inherit; font-size: 0.83rem; font-weight: 600;
  cursor: pointer; border: none; text-decoration: none;
  transition: all 0.15s; white-space: nowrap; line-height: 1;
}

.btn-primary { background: var(--accent); color: var(--bg); }
.btn-primary:hover { background: var(--accent2); box-shadow: 0 4px 16px rgba(200,169,106,0.3); transform: translateY(-1px); }

.btn-secondary { background: var(--bg4); color: var(--text2); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); color: var(--text1); }

.btn-danger { background: rgba(224,80,80,0.1); color: var(--danger); border: 1px solid rgba(224,80,80,0.2); }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-success { background: rgba(61,184,122,0.1); color: var(--success); border: 1px solid rgba(61,184,122,0.2); }
.btn-success:hover { background: var(--success); color: #fff; }

.btn-ghost { background: transparent; color: var(--text2); }
.btn-ghost:hover { background: var(--bg4); color: var(--text1); }

.btn-sm { padding: 5px 11px; font-size: 0.77rem; border-radius: 7px; }
.btn-xs { padding: 3px 8px; font-size: 0.72rem; border-radius: 6px; }
.btn-icon { padding: 7px; }
.btn-w { width: 100%; justify-content: center; }

/* ══════════════ FORMS ══════════════ */
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 5px; font-size: 0.78rem; font-weight: 600; color: var(--text2); }
.required-star { color: var(--danger); margin-inline-start: 3px; }

.form-control {
  width: 100%; padding: 9px 12px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 9px; color: var(--text1);
  font-family: inherit; font-size: 0.85rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accentbg); }
.form-control::placeholder { color: var(--text3); }
select.form-control option { background: var(--bg2); }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* ══════════════ BADGES ══════════════ */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 9px; border-radius: 20px;
  font-size: 0.71rem; font-weight: 600;
}
.b-gold   { background: rgba(200,169,106,0.12); color: var(--accent);   border: 1px solid rgba(200,169,106,0.25); }
.b-blue   { background: rgba(91,141,238,0.12);  color: var(--info);     border: 1px solid rgba(91,141,238,0.25); }
.b-green  { background: rgba(61,184,122,0.12);  color: var(--success);  border: 1px solid rgba(61,184,122,0.25); }
.b-red    { background: rgba(224,80,80,0.12);   color: var(--danger);   border: 1px solid rgba(224,80,80,0.25); }
.b-orange { background: rgba(232,158,58,0.12);  color: var(--warn);     border: 1px solid rgba(232,158,58,0.25); }
.b-gray   { background: var(--bg4);             color: var(--text3);    border: 1px solid var(--border); }
.b-purple { background: rgba(150,80,224,0.12);  color: #9650e0;         border: 1px solid rgba(150,80,224,0.25); }

/* ══════════════ MODAL ══════════════ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(6px);
  display: none; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; animation: fadeIn 0.2s ease; }

.modal {
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: 16px; padding: 26px;
  width: 100%; max-width: 540px; max-height: 90vh;
  overflow-y: auto; box-shadow: var(--shadow2);
  animation: slideUp 0.25s ease;
}
.modal-lg { max-width: 720px; }

.modal-title {
  font-size: 1rem; font-weight: 700; color: var(--text1);
  margin-bottom: 18px; padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}

@keyframes slideUp { from { opacity:0; transform:translateY(16px); } to { opacity:1; transform:translateY(0); } }
@keyframes fadeIn  { from { opacity:0; } to { opacity:1; } }

/* ══════════════ ALERTS ══════════════ */
.alert { padding: 11px 15px; border-radius: 9px; font-size: 0.83rem; margin-bottom: 14px; border-inline-start: 3px solid; }
.alert-err  { background: rgba(224,80,80,0.08);   border-color: var(--danger);  color: #ff8888; }
.alert-ok   { background: rgba(61,184,122,0.08);  border-color: var(--success); color: #66cc99; }
.alert-warn { background: rgba(232,158,58,0.08);  border-color: var(--warn);    color: #ffaa55; }

/* ══════════════ KANBAN ══════════════ */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.kanban-col { min-width: 280px; background: var(--bg3); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.kanban-col-hdr { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text3); margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; }
.kanban-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 8px; transition: all 0.15s; cursor: pointer; }
.kanban-card:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow); }

/* ══════════════ CHAT ══════════════ */
.chat-layout { display: grid; grid-template-columns: 260px 1fr; gap: 0; height: calc(100vh - var(--topbar-h) - 48px); min-height: 400px; }
.chat-pane { border: 1px solid var(--border); background: var(--bg2); }
.chat-sidebar { border-radius: 14px 0 0 14px; overflow-y: auto; }
.chat-main { border-inline-start: none; border-radius: 0 14px 14px 0; display: flex; flex-direction: column; }
[dir="ltr"] .chat-sidebar { border-radius: 14px 0 0 14px; }
[dir="ltr"] .chat-main { border-left: none; border-radius: 0 14px 14px 0; }
[dir="rtl"] .chat-sidebar { border-radius: 0 14px 14px 0; }
[dir="rtl"] .chat-main { border-right: none; border-radius: 14px 0 0 14px; }

.chat-contact { padding: 12px 14px; display: flex; align-items: center; gap: 10px; cursor: pointer; border-bottom: 1px solid var(--border); transition: background 0.1s; }
.chat-contact:hover { background: var(--bg4); }
.chat-contact.active { background: var(--accentbg); }

.chat-messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { max-width: 72%; }
.chat-msg-bubble { padding: 9px 13px; border-radius: 12px; font-size: 0.84rem; line-height: 1.45; word-break: break-word; }
.chat-msg.out { align-self: flex-end; }
.chat-msg.out .chat-msg-bubble { background: var(--accentbg); border: 1px solid rgba(200,169,106,0.2); color: var(--accent2); }
.chat-msg.in .chat-msg-bubble { background: var(--bg4); border: 1px solid var(--border); }
.chat-msg-meta { font-size: 0.68rem; color: var(--text3); margin-top: 3px; }
.chat-msg.out .chat-msg-meta { text-align: end; }
.chat-input-row { padding: 14px; border-top: 1px solid var(--border); display: flex; gap: 8px; }

/* ══════════════ DOCUMENT PREVIEW ══════════════ */
.doc-preview-wrap { border-radius: 12px; overflow: hidden; border: 1px solid var(--border); background: var(--bg3); min-height: 500px; display: flex; align-items: center; justify-content: center; }
.doc-preview-wrap iframe { width: 100%; height: 70vh; border: none; }
.doc-preview-wrap img { max-width: 100%; max-height: 70vh; object-fit: contain; padding: 20px; }
.doc-no-preview { text-align: center; padding: 60px 20px; color: var(--text3); }

/* ══════════════ PERMISSIONS TABLE ══════════════ */
.perm-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.perm-badge { font-size: 0.72rem; font-weight: 700; padding: 3px 10px; border-radius: 20px; }

/* ══════════════ PROGRESS BARS ══════════════ */
.progress-bar { background: var(--bg4); border-radius: 8px; height: 6px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 8px; background: var(--accent); transition: width 0.4s ease; }

/* ══════════════ EMPTY STATE ══════════════ */
.empty { text-align: center; padding: 48px 20px; color: var(--text3); }
.empty svg { opacity: 0.15; margin-bottom: 12px; }
.empty h3 { font-size: 0.95rem; color: var(--text2); margin-bottom: 5px; }
.empty p { font-size: 0.8rem; }

/* ══════════════ UTILITIES ══════════════ */
.flex { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.mb-4 { margin-bottom: 16px; } .mb-5 { margin-bottom: 20px; } .mb-6 { margin-bottom: 24px; }
.mt-4 { margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-main { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid-2,.grid-3,.grid-main { grid-template-columns: 1fr; } }
.text-muted { color: var(--text3); font-size: 0.78rem; }
.text-accent { color: var(--accent); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.fw-700 { font-weight: 700; }
.w-full { width: 100%; }
.separator { height: 1px; background: var(--border); margin: 14px 0; }

/* ══════════════ SCROLLBAR ══════════════ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ══════════════ NOTIFICATION DROPDOWN ══════════════ */
.notif-btn { position: relative; }
.notif-dot { position: absolute; top: 5px; inset-inline-end: 5px; width: 7px; height: 7px; background: var(--danger); border-radius: 50%; border: 2px solid var(--bg2); }
.notif-dropdown {
  position: fixed;
  top: 60px;
  right: 10px;
  width: 320px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  z-index: 9999;
  display: none;
  overflow: hidden;
  max-height: calc(100dvh - 80px);
  overflow-y: auto;
}
.notif-dropdown.open { display: block; animation: slideUp 0.2s ease; }
.notif-header { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 0.83rem; font-weight: 700; display: flex; justify-content: space-between; }
.notif-item { padding: 11px 16px; border-bottom: 1px solid var(--border); transition: background 0.1s; cursor: pointer; }
.notif-item:hover { background: var(--bg4); }
.notif-item.unread { background: var(--accentbg); }
.notif-item:last-child { border-bottom: none; }

/* ══════════════ AUTH PAGES ══════════════ */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.auth-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 18px; padding: 40px; width: 100%; max-width: 440px; box-shadow: var(--shadow2); }
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo .logo-icon { margin: 0 auto 10px; width: 52px; height: 52px; font-size: 1.7rem; }
.auth-logo h1 { font-size: 1.5rem; font-weight: 800; color: var(--text1); }
.auth-logo p { font-size: 0.8rem; color: var(--text3); margin-top: 4px; }

/* ══════════════ LANDING HEADER ══════════════ */
.landing-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; background: var(--bg2); border-bottom: 1px solid var(--border); }
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ══════════════ STATUS COLORS ══════════════ */
.s-intake     { --c: var(--info); }
.s-review     { --c: var(--warn); }
.s-inprogress { --c: #5b8dee; }
.s-incourt    { --c: var(--danger); }
.s-issued     { --c: var(--success); }
.s-closed     { --c: var(--text3); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--text3)); display: inline-block; margin-inline-end: 6px; }

/* ══════════════ PRIORITY ══════════════ */
.pri-high   { color: var(--danger); }
.pri-medium { color: var(--warn); }
.pri-low    { color: var(--success); }

/* ══════════════ TABS ══════════════ */
.tabs { display: flex; gap: 2px; background: var(--bg4); border-radius: 10px; padding: 3px; margin-bottom: 18px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex-shrink: 0; white-space: nowrap; }
.tab { padding: 7px 16px; border-radius: 8px; font-size: 0.82rem; font-weight: 600; cursor: pointer; color: var(--text2); border: none; background: transparent; font-family: inherit; transition: all 0.15s; }
.tab.active { background: var(--bg2); color: var(--text1); box-shadow: var(--shadow); }



/* ════════════════════════════════════════════════════════
   MOBILE — Complete rewrite v2
════════════════════════════════════════════════════════ */

/* ── Stats grid responsive ── */
.stats-grid { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; } }
@media (max-width: 480px) { .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; } }

/* ── Sidebar drawer ── */
@media (max-width: 768px) {
  :root { --sw: 0px; }

  .sidebar {
    position: fixed;
    top: 0; bottom: 0;
    inset-inline-start: 0;
    width: 260px !important;
    z-index: 400;
    transform: translateX(-110%);
    transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  [dir="rtl"] .sidebar { transform: translateX(110%); }
  .sidebar.open {
    transform: translateX(0) !important;
    box-shadow: 0 0 50px rgba(0,0,0,0.4);
  }

  .main { margin-inline-start: 0 !important; width: 100% !important; }

  #hamburger { display: flex !important; flex-shrink: 0; }

  /* Topbar — fixed height, no wrap */
  .topbar {
    padding: 0 10px;
    height: 52px;
    gap: 4px;
    flex-wrap: nowrap;
    overflow: hidden;
  }
  .page-title {
    font-size: 0.85rem;
    max-width: 110px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
  }
  /* Hide search bar */
  .topbar > div:nth-child(2) { display: none !important; }
  /* Compact topbar right */
  .topbar-right { gap: 1px; flex-shrink: 0; }
  .topbar-right .btn-sm { font-size: 0.7rem; padding: 4px 7px; }
  /* Hide lang toggle text */
  .topbar-right form:has([name=lang]) button { font-size: 0.72rem; padding: 4px 6px; }

  .content { padding: 10px 8px 30px; }

  #sideOverlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 349;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }
  #sideOverlay.open { display: block; }
}

@media (min-width: 769px) {
  #hamburger { display: none !important; }
  #sideOverlay { display: none !important; }
}

/* ── Stat cards on mobile ── */
@media (max-width: 768px) {
  .stat-card { padding: 12px 10px; gap: 10px; border-radius: 12px; }
  .stat-icon { width: 36px; height: 36px; border-radius: 9px; }
  .stat-icon svg { width: 18px; height: 18px; }
  .stat-val   { font-size: 1.4rem; }
  .stat-label { font-size: 0.68rem; }
}

/* ── Grids ── */
@media (max-width: 768px) {
  .grid-main, .grid-2, .grid-3 { grid-template-columns: 1fr !important; }
  .form-grid-2, .form-grid-3   { grid-template-columns: 1fr !important; }
}

/* ── Cards ── */
@media (max-width: 768px) {
  .card { padding: 12px; border-radius: 12px; }
  .card-title { font-size: 0.9rem; }
}

/* ── Tables ── */
@media (max-width: 768px) {
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 480px; font-size: 0.8rem; }
  th, td { padding: 7px 9px; white-space: nowrap; }
}

/* ── Modals — bottom sheet ── */
@media (max-width: 640px) {
  .modal-overlay { align-items: flex-end !important; padding: 0 !important; }
  .modal {
    border-radius: 18px 18px 0 0 !important;
    max-height: 88vh; overflow-y: auto;
    padding: 18px 14px;
    width: 100% !important; margin: 0 !important;
    animation: slideUp 0.22s cubic-bezier(0.4,0,0.2,1);
  }
  .modal-lg { max-height: 92vh; }
  @keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
}

/* ── Kanban ── */
@media (max-width: 768px) {
  .kanban { overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 10px; padding-bottom: 8px; }
  .kanban::-webkit-scrollbar { height: 3px; }
  .kanban-col { min-width: 220px; }
}

/* ── Tabs ── */
@media (max-width: 640px) {
  .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; font-size: 0.73rem; padding: 5px 9px; }
}

/* ── Buttons ── */
@media (max-width: 480px) {
  .btn-sm { font-size: 0.73rem; padding: 5px 8px; }
  .flex-between { flex-wrap: wrap; gap: 8px; }
}

/* ── Notifications ── */
@media (max-width: 480px) {
  .notif-dropdown { width: calc(100vw - 16px); inset-inline-end: -30px; max-height: 65vh; }
}

/* ── Documents grid ── */
@media (max-width: 640px) {
  .fm-grid { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)) !important; gap: 5px !important; padding: 8px !important; }
  .fm-ico { font-size: 1.8rem !important; }
  .fm-name { font-size: 0.67rem !important; }
}

/* ════════════════════════════════════════════════
   CHAT MOBILE — full rewrite
════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Chat layout fills screen */
  #chatLayout {
    border-radius: 0;
    border: none;
    margin: -10px -8px;
    height: calc(100dvh - 52px);
    max-height: calc(100dvh - 52px);
  }
  /* Sidebar = full page */
  #chatSidebar {
    width: 100%;
    border-inline-end: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Chat panel = slide over */
  #chatMain {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 10;
    background: var(--bg2);
    flex-direction: column;
  }
  #chatMain.mob { display: flex; }
  #backBtn { display: flex !important; }

  /* Input bar bigger touch targets */
  .input-row { padding: 8px 10px; gap: 5px; }
  .input-row .btn-icon { width: 38px; height: 38px; }
  #msgIn { font-size: 16px; } /* prevent iOS zoom */
}

/* ════════════════════════════════════════════════
   TOUCH DELETE — show on long press / tap on mobile
════════════════════════════════════════════════ */

/* On touch devices, show delete on tap instead of hover */
@media (hover: none) and (pointer: coarse) {
  /* Chat delete button — always visible on mobile */
  .chat-del-btn {
    display: flex !important;
    opacity: 0.7;
  }
  .mc-del-btn {
    display: flex !important;
    opacity: 0.7;
  }
  /* But only on OWN messages (out) */
  .msg-row.in .chat-del-btn  { display: none !important; }
  .mc-msg.in  .mc-del-btn    { display: none !important; }
}

/* ── Misc mobile fixes ── */
@media (max-width: 768px) {
  /* Prevent iOS input zoom */
  input[type="text"], input[type="email"], input[type="password"],
  input[type="search"], select, textarea { font-size: 16px !important; }

  /* Better scroll on matter detail tabs */
  .tab-panel { overflow-y: auto; }

  /* Safe area for notch */
  .topbar { padding-top: env(safe-area-inset-top, 0px); }
}

/* ════════════════════════════════════════════════
   MATTER DETAIL MOBILE FIXES
════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Quick stats mini cards inside matter */
  .matter-mini-stat {
    padding: 10px 8px !important;
  }
  .matter-mini-stat .stat-num {
    font-size: 1.2rem !important;
  }

  /* Grid inside matter detail side column */
  [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }

  /* Matter info table */
  #tab-info table td:first-child {
    width: 100px !important;
    font-size: 0.78rem;
  }

  /* Tab panel scroll */
  .tab-panel {
    min-height: 0;
  }

  /* Matter chat area height */
  #mcMsgs {
    max-height: calc(100dvh - 280px);
  }

  /* Docs browser on matter mobile */
  #docsBrowser {
    min-height: 120px;
  }

  /* Action buttons in matter header */
  .flex-between .flex { flex-wrap: wrap; gap: 6px; }
}

@media (max-width: 480px) {
  /* Very small: matter quick stats 2x2 */
  #tab-info [style*="grid-template-columns:1fr 1fr"] div {
    padding: 8px 6px !important;
  }
  #tab-info [style*="font-size:1.4rem"] {
    font-size: 1.1rem !important;
  }
}

/* ── Mobile Actions Bar ── */
/* Desktop: hidden — buttons stay in topbar */
.mobile-actions { display: none; }

@media (max-width: 768px) {
  /* Show below topbar on mobile — only if has content */
  .mobile-actions:not(:empty) {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 8px 10px 4px;
    flex-wrap: wrap;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }
  .mobile-actions .btn { font-size: 0.82rem; }

  /* Hide topbar extra buttons on mobile — shown in mobile-actions instead */
  .topbar-extra-desktop { display: none !important; }
}

@media (min-width: 769px) {
  /* On desktop: hide mobile bar, show topbar extra */
  .mobile-actions { display: none !important; }
  .topbar-extra-desktop { display: contents; }
}








/* ══ Dashboard Mobile ══ */
@media (max-width: 768px) {
  /* Stack columns */
  .grid-main { grid-template-columns: 1fr !important; gap: 12px; }

  /* Recent matters: fixed height + scroll */
  #dash-recent {
    max-height: 320px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #dash-recent .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  #dash-recent table { min-width: 400px; }

  /* Right column: horizontal scroll — tasks & events side by side */
  #dash-right {
    flex-direction: row !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 10px;
    padding-bottom: 4px;
  }
  #dash-right::-webkit-scrollbar { display: none; }

  #dash-tasks, #dash-events {
    min-width: 76vw;
    max-width: 76vw;
    flex-shrink: 0;
    max-height: 280px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}
