/* ============================================================
   Tamm Mail System — premium enterprise design system
   Light/Dark via [data-theme]; RTL via [dir="rtl"].
   Uses CSS logical properties so a single rule serves LTR + RTL.
   ============================================================ */
:root {
    /* Brand */
    --tm-brand-1: #1a73e8;
    --tm-brand-2: #4f8ff7;
    --tm-brand-3: #8ab4f8;

    /* Surfaces & text (light) */
    --tm-bg: #f1f4f9;
    --tm-surface: #ffffff;
    --tm-surface-2: #eef1f6;
    --tm-surface-3: #e4e8f0;
    --tm-border: #e3e8ef;
    --tm-border-strong: #cdd5e0;
    --tm-text: #1b1f27;
    --tm-text-2: #424955;
    --tm-text-muted: #6b7280;

    /* Semantic */
    --tm-primary: #1a73e8;
    --tm-primary-soft: #e8f0fe;
    --tm-primary-contrast: #ffffff;
    --tm-danger: #d93025;
    --tm-danger-soft: #fce8e6;
    --tm-warning: #e8710a;
    --tm-warning-soft: #fef3e2;
    --tm-success: #1e8e3e;
    --tm-success-soft: #e6f4ea;
    --tm-purple: #8430ce;
    --tm-purple-soft: #f3e8fd;
    --tm-star: #f4b400;

    /* Elevation */
    --tm-shadow-sm: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.05);
    --tm-shadow: 0 2px 6px rgba(16,24,40,.06), 0 4px 12px rgba(16,24,40,.05);
    --tm-shadow-lg: 0 8px 24px rgba(16,24,40,.12), 0 2px 6px rgba(16,24,40,.06);
    --tm-ring: 0 0 0 3px rgba(26,115,232,.25);

    /* Geometry */
    --tm-radius-sm: 8px;
    --tm-radius: 14px;
    --tm-radius-lg: 20px;
    --tm-sidebar-w: 264px;
    --tm-topbar-h: 64px;

    --tm-ease: cubic-bezier(.2,.7,.3,1);
    --tm-font: "Inter", "Segoe UI Variable", "Segoe UI", "Tahoma", system-ui, -apple-system, "Helvetica Neue", Arial, "Noto Sans Arabic", sans-serif;
}

[data-theme="dark"] {
    --tm-bg: #16181d;
    --tm-surface: #21242b;
    --tm-surface-2: #282c34;
    --tm-surface-3: #31353e;
    --tm-border: #343a44;
    --tm-border-strong: #424a56;
    --tm-text: #e8eaed;
    --tm-text-2: #c2c7d0;
    --tm-text-muted: #949aa6;

    --tm-primary: #8ab4f8;
    --tm-primary-soft: #29354a;
    --tm-primary-contrast: #16181d;
    --tm-danger-soft: #3a2422;
    --tm-warning-soft: #3a2e1c;
    --tm-success-soft: #1d3025;
    --tm-purple-soft: #2f2440;
    --tm-shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --tm-shadow: 0 2px 8px rgba(0,0,0,.45);
    --tm-shadow-lg: 0 12px 28px rgba(0,0,0,.55);
    --tm-ring: 0 0 0 3px rgba(138,180,248,.3);
}

* { box-sizing: border-box; }

/* ---------- Icons (Bootstrap Icons) ---------- */
/* Consistent baseline alignment + sizing across the whole app. */
.bi { display: inline-block; vertical-align: -0.125em; line-height: 1; }
.tm-btn .bi { font-size: 1.05em; }
.tm-iconbtn .bi { font-size: 19px; }
.tm-stat .ic .bi { font-size: 22px; }
.tm-nav a .ico.bi { font-size: 18px; width: 22px; text-align: center; }
.tm-compose-btn .bi { font-size: 17px; }
.tm-toolbar h1 .bi, .page-title .bi { vertical-align: -0.12em; }
/* subtle, professional hover for clickable standalone icons */
.tm-iconbtn .bi { transition: transform .12s var(--tm-ease); }
.tm-iconbtn:hover .bi { transform: scale(1.08); }

html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--tm-font);
    background: var(--tm-bg);
    color: var(--tm-text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a { color: var(--tm-primary); text-decoration: none; }
a:hover { text-decoration: none; }
::selection { background: var(--tm-primary-soft); }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--tm-border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--tm-border-strong); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }

/* ---------- App shell ---------- */
.tm-app { display: grid; grid-template-rows: var(--tm-topbar-h) 1fr; min-height: 100vh; }

.tm-topbar {
    display: flex; align-items: center; gap: 14px;
    padding-inline: 18px;
    background: color-mix(in srgb, var(--tm-surface) 88%, transparent);
    backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--tm-border);
    position: sticky; top: 0; z-index: 50;
}
.tm-brand { display: flex; align-items: center; gap: 11px; font-weight: 700; font-size: 19px; color: var(--tm-text); letter-spacing: -.01em; }
.tm-brand:hover { color: var(--tm-text); }
.tm-logo {
    width: 38px; height: 38px; border-radius: 11px;
    background: linear-gradient(135deg, var(--tm-brand-1), var(--tm-brand-3));
    display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 18px;
    box-shadow: 0 4px 10px rgba(26,115,232,.35);
}

.tm-search {
    flex: 1; max-width: 680px; display: flex; align-items: center; gap: 10px;
    background: var(--tm-surface-2); border-radius: 999px; padding: 9px 18px;
    border: 1px solid transparent; transition: background .15s, box-shadow .15s, border-color .15s;
}
.tm-search:focus-within { background: var(--tm-surface); border-color: var(--tm-border-strong); box-shadow: var(--tm-shadow); }
.tm-search .i { color: var(--tm-text-muted); font-size: 16px; display: grid; place-items: center; }
.tm-search input { flex: 1; border: 0; background: transparent; color: var(--tm-text); outline: none; font-size: 14px; font-family: inherit; }
.tm-topbar-actions { display: flex; align-items: center; gap: 4px; margin-inline-start: auto; }

.tm-iconbtn {
    width: 42px; height: 42px; border: 0; border-radius: 50%;
    background: transparent; color: var(--tm-text-2); cursor: pointer;
    display: grid; place-items: center; font-size: 18px; position: relative;
    transition: background .15s var(--tm-ease), color .15s, transform .08s;
}
.tm-iconbtn:hover { background: var(--tm-surface-2); color: var(--tm-text); }
.tm-iconbtn:active { transform: scale(.92); }
.tm-iconbtn:focus-visible { outline: none; box-shadow: var(--tm-ring); }
.tm-badge {
    position: absolute; top: 5px; inset-inline-end: 5px; min-width: 17px; height: 17px;
    padding: 0 4px; border-radius: 999px; background: var(--tm-danger); color: #fff;
    font-size: 10px; line-height: 17px; text-align: center; font-weight: 700;
    box-shadow: 0 0 0 2px var(--tm-surface);
}

.tm-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: linear-gradient(135deg, var(--tm-brand-1), var(--tm-brand-3));
    color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 15px;
    flex-shrink: 0; user-select: none;
}
.tm-avatar.sm { width: 32px; height: 32px; font-size: 13px; }
.tm-avatar.c1 { background: linear-gradient(135deg,#1a73e8,#8ab4f8); }
.tm-avatar.c2 { background: linear-gradient(135deg,#8430ce,#c79bf2); }
.tm-avatar.c3 { background: linear-gradient(135deg,#1e8e3e,#76d295); }
.tm-avatar.c4 { background: linear-gradient(135deg,#e8710a,#f7b267); }
.tm-avatar.c5 { background: linear-gradient(135deg,#d93025,#f08a82); }
.tm-avatar.c6 { background: linear-gradient(135deg,#0b8043,#5bbf86); }

/* ---------- Body layout ---------- */
.tm-body { display: grid; grid-template-columns: var(--tm-sidebar-w) minmax(0, 1fr); min-height: 0; min-width: 0; }
/* The mobile scrim must stay out of the desktop grid flow; it only becomes a
   fixed overlay (and visible) inside the mobile breakpoint when .open is set.
   Without this base rule it renders as an in-flow grid item on desktop, stealing
   the sidebar's column and forcing the main content onto a new grid row. */
.tm-scrim { display: none; }
.tm-sidebar {
    padding: 16px 14px; overflow-y: auto;
    border-inline-end: 1px solid var(--tm-border);
    background: var(--tm-surface);
}
.tm-content { padding: 22px clamp(16px, 3vw, 36px); min-width: 0; max-width: 1440px; width: 100%; margin-inline: auto; }

.tm-compose-btn {
    display: inline-flex; align-items: center; gap: 12px; width: 100%;
    padding: 14px 22px; border: 0; border-radius: var(--tm-radius);
    background: linear-gradient(135deg, var(--tm-brand-1), var(--tm-brand-2));
    color: #fff; box-shadow: 0 6px 16px rgba(26,115,232,.35);
    font-size: 15px; font-weight: 700; cursor: pointer; margin-bottom: 18px;
    transition: transform .12s var(--tm-ease), box-shadow .15s; justify-content: center;
}
.tm-compose-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(26,115,232,.42); color: #fff; }
.tm-compose-btn:active { transform: translateY(0); }

.tm-section-label { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--tm-text-muted); padding: 14px 16px 6px; }
.tm-nav { list-style: none; margin: 0; padding: 0; }
.tm-nav a {
    display: flex; align-items: center; gap: 14px;
    padding: 10px 16px; border-radius: 999px; color: var(--tm-text-2);
    margin-bottom: 2px; font-weight: 500; position: relative;
    transition: background .14s var(--tm-ease), color .14s;
}
.tm-nav a .ico { width: 22px; text-align: center; font-size: 17px; flex-shrink: 0; }
.tm-nav a:hover { background: var(--tm-surface-2); color: var(--tm-text); }
.tm-nav a.active { background: var(--tm-primary-soft); color: var(--tm-primary); font-weight: 700; }
.tm-nav a.active .ico { filter: saturate(1.2); }
.tm-nav .count { margin-inline-start: auto; font-size: 12px; font-weight: 700; color: var(--tm-text-muted); background: var(--tm-surface-2); padding: 1px 8px; border-radius: 999px; }
.tm-nav a.active .count { background: color-mix(in srgb, var(--tm-primary) 18%, transparent); color: var(--tm-primary); }

/* ---------- Card ---------- */
.tm-card { background: var(--tm-surface); border: 1px solid var(--tm-border); border-radius: var(--tm-radius); box-shadow: var(--tm-shadow-sm); overflow: hidden; }
.tm-toolbar { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--tm-border); }
.tm-toolbar h1 { font-size: 17px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.page-title { font-size: 23px; font-weight: 800; letter-spacing: -.02em; margin: 2px 0 20px; }

/* ---------- Mail list ---------- */
.tm-list { list-style: none; margin: 0; padding: 0; }
.tm-row {
    display: flex; align-items: center; gap: 13px; padding: 12px 18px;
    border-bottom: 1px solid var(--tm-border); cursor: pointer;
    transition: background .12s, box-shadow .12s; position: relative;
}
.tm-row:last-child { border-bottom: 0; }
.tm-row:hover { background: var(--tm-surface-2); box-shadow: inset 3px 0 0 var(--tm-primary); z-index: 1; }
[dir="rtl"] .tm-row:hover { box-shadow: inset -3px 0 0 var(--tm-primary); }
.tm-row.unread { background: color-mix(in srgb, var(--tm-primary-soft) 35%, var(--tm-surface)); }
.tm-row.unread .tm-row-from, .tm-row.unread .tm-row-subject { font-weight: 700; color: var(--tm-text); }
.tm-row.unread::before { content: ""; position: absolute; inset-inline-start: 6px; top: 50%; width: 6px; height: 6px; border-radius: 50%; background: var(--tm-primary); transform: translateY(-50%); }
.tm-row-from { width: 190px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--tm-text-2); }
.tm-row-main { flex: 1; overflow: hidden; display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.tm-row-subject { color: var(--tm-text); font-weight: 500; white-space: nowrap; }
.tm-row-snippet { color: var(--tm-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tm-row-date { width: 92px; text-align: end; flex-shrink: 0; color: var(--tm-text-muted); font-size: 12px; font-weight: 600; }
.tm-star { color: var(--tm-border-strong); cursor: pointer; background: none; border: 0; font-size: 17px; line-height: 1; padding: 2px; border-radius: 6px; transition: transform .1s, color .12s; }
.tm-star:hover { color: var(--tm-star); transform: scale(1.18); }
.tm-star.on { color: var(--tm-star); }

.tm-chip { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .01em; white-space: nowrap; }
.tm-chip.prio-Urgent { background: var(--tm-danger-soft); color: var(--tm-danger); }
.tm-chip.prio-High { background: var(--tm-warning-soft); color: var(--tm-warning); }
.tm-chip.conf-Confidential, .tm-chip.conf-Secret { background: var(--tm-purple-soft); color: var(--tm-purple); }

/* ---------- Reading pane ---------- */
.tm-read { padding: 26px clamp(18px,3vw,34px); }
.tm-read h1 { font-size: 24px; margin: 0 0 18px; font-weight: 800; letter-spacing: -.02em; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tm-read-meta { display: flex; align-items: center; gap: 13px; margin-bottom: 20px; padding-bottom: 18px; border-bottom: 1px solid var(--tm-border); }
.tm-read-body { line-height: 1.75; color: var(--tm-text-2); font-size: 15px; }
.tm-read-body img { max-width: 100%; border-radius: 8px; }
.tm-attach-item { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border: 1px solid var(--tm-border); border-radius: 10px; margin: 4px 6px 4px 0; background: var(--tm-surface-2); }

/* ---------- Conversation thread ---------- */
.tm-thread { display: flex; flex-direction: column; gap: 12px; }
.tm-msg { border: 1px solid var(--tm-border); border-radius: var(--tm-radius); background: var(--tm-surface); overflow: hidden; transition: box-shadow .15s; }
.tm-msg.expanded { box-shadow: var(--tm-shadow-sm); }
.tm-msg-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer; }
.tm-msg-head:hover { background: var(--tm-surface-2); }
.tm-msg-body { padding: 4px 18px 20px; }
/* collapsed: hide body + recipients, show snippet */
.tm-msg.collapsed .tm-msg-body { display: none; }
.tm-msg.collapsed .tm-msg-recipients { display: none; }
.tm-msg.expanded .tm-msg-collapsed-snippet { display: none; }
/* Gmail/Outlook-style From/To/CC/BCC detail block */
.tm-recipients { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; font-size: 12.5px; color: var(--tm-text-muted); }
.tm-recipients .row { display: flex; gap: 8px; align-items: baseline; }
.tm-recipients .lbl { min-width: 52px; font-weight: 700; color: var(--tm-text-muted); flex-shrink: 0; }
.tm-recipients .row > span:last-child { min-width: 0; word-break: break-word; }
.tm-addr { color: var(--tm-text-muted); unicode-bidi: isolate; direction: ltr; }
@media (max-width: 520px) {
    .tm-recipients .row { flex-direction: column; gap: 0; }
    .tm-recipients .lbl { min-width: 0; }
}

/* ---------- Buttons ---------- */
.tm-btn {
    display: inline-flex; align-items: center; gap: 8px; padding: 9px 18px;
    border-radius: 999px; border: 1px solid var(--tm-border-strong); background: var(--tm-surface);
    color: var(--tm-text); font-weight: 600; cursor: pointer; font-size: 14px; font-family: inherit;
    transition: background .14s, border-color .14s, transform .08s, box-shadow .14s; white-space: nowrap;
}
.tm-btn:hover { background: var(--tm-surface-2); color: var(--tm-text); border-color: var(--tm-border-strong); }
.tm-btn:active { transform: scale(.97); }
.tm-btn:focus-visible { outline: none; box-shadow: var(--tm-ring); }
.tm-btn-primary { background: linear-gradient(135deg, var(--tm-brand-1), var(--tm-brand-2)); color: #fff; border-color: transparent; box-shadow: 0 4px 12px rgba(26,115,232,.3); }
.tm-btn-primary:hover { color: #fff; filter: brightness(1.04); box-shadow: 0 6px 16px rgba(26,115,232,.4); }
.tm-btn-ghost { border-color: transparent; background: transparent; }
.tm-btn-ghost:hover { background: var(--tm-surface-2); }
.tm-btn-danger { color: var(--tm-danger); border-color: var(--tm-border); }
.tm-btn-danger:hover { background: var(--tm-danger-soft); border-color: var(--tm-danger); }

/* ---------- Forms ---------- */
.tm-field { margin-bottom: 16px; }
.tm-field label { display: block; font-size: 12px; font-weight: 600; color: var(--tm-text-2); margin-bottom: 6px; letter-spacing: .01em; }
.tm-input, .tm-select, .tm-textarea {
    width: 100%; padding: 11px 14px; border-radius: var(--tm-radius-sm);
    border: 1px solid var(--tm-border-strong); background: var(--tm-surface); color: var(--tm-text);
    font-size: 14px; font-family: inherit; transition: border-color .14s, box-shadow .14s, background .14s;
}
.tm-input::placeholder, .tm-textarea::placeholder { color: var(--tm-text-muted); }
.tm-input:focus, .tm-textarea:focus, .tm-select:focus { outline: none; border-color: var(--tm-primary); box-shadow: var(--tm-ring); }
.tm-textarea { min-height: 260px; resize: vertical; line-height: 1.65; }
.tm-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tm-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

/* ---------- Dashboard ---------- */
.tm-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 18px; margin-bottom: 22px; }
.tm-stat { padding: 20px; display: flex; align-items: center; gap: 16px; position: relative; transition: transform .14s var(--tm-ease), box-shadow .14s; text-decoration: none; color: inherit; }
.tm-stat:hover { transform: translateY(-2px); box-shadow: var(--tm-shadow); color: inherit; }
.tm-stat::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 4px; background: var(--tm-accent, var(--tm-primary)); }
.tm-stat .ic { width: 50px; height: 50px; border-radius: 13px; display: grid; place-items: center; font-size: 22px; background: var(--tm-accent-soft, var(--tm-primary-soft)); color: var(--tm-accent, var(--tm-primary)); flex-shrink: 0; }
.tm-stat .num { font-size: 28px; font-weight: 800; line-height: 1.1; letter-spacing: -.02em; }
.tm-stat .lbl { color: var(--tm-text-muted); font-size: 13px; font-weight: 600; }
.tm-stat.a-blue   { --tm-accent: #1a73e8; --tm-accent-soft: var(--tm-primary-soft); }
.tm-stat.a-green  { --tm-accent: #1e8e3e; --tm-accent-soft: var(--tm-success-soft); }
.tm-stat.a-orange { --tm-accent: #e8710a; --tm-accent-soft: var(--tm-warning-soft); }
.tm-stat.a-purple { --tm-accent: #8430ce; --tm-accent-soft: var(--tm-purple-soft); }

.tm-dash-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 18px; align-items: start; }

/* pure-CSS bar chart */
.tm-chart { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding: 14px 18px 0; }
.tm-chart .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; }
.tm-chart .bar > i { width: 100%; max-width: 34px; border-radius: 8px 8px 0 0; background: linear-gradient(180deg, var(--tm-brand-2), var(--tm-brand-1)); transition: height .5s var(--tm-ease); display: block; }
.tm-chart .bar > span { font-size: 11px; color: var(--tm-text-muted); font-weight: 600; }

.tm-quick { display: flex; flex-direction: column; gap: 10px; padding: 16px 18px; }
.tm-quick a { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--tm-radius-sm); background: var(--tm-surface-2); color: var(--tm-text); font-weight: 600; transition: transform .12s, background .14s; }
.tm-quick a:hover { background: var(--tm-surface-3); transform: translateX(2px); }
[dir="rtl"] .tm-quick a:hover { transform: translateX(-2px); }

/* ---------- AI toolbar ---------- */
.tm-ai-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 12px 0; padding: 12px 14px; background: linear-gradient(135deg, color-mix(in srgb,var(--tm-purple-soft) 60%, var(--tm-surface)), var(--tm-primary-soft)); border: 1px solid var(--tm-border); border-radius: var(--tm-radius); }
.tm-ai-bar .lead { font-weight: 700; color: var(--tm-purple); display: inline-flex; align-items: center; gap: 6px; }
.tm-ai-bar .tm-btn { padding: 7px 14px; font-size: 13px; }
.tm-ai-suggestions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 8px; }
.tm-ai-suggestions button { background: var(--tm-primary-soft); color: var(--tm-primary); border: 1px solid transparent; border-radius: 999px; padding: 9px 17px; cursor: pointer; font-size: 13px; font-weight: 600; font-family: inherit; transition: transform .1s, box-shadow .14s; }
.tm-ai-suggestions button:hover { transform: translateY(-1px); box-shadow: var(--tm-shadow-sm); }

/* ---------- Attachment dropzone ---------- */
.tm-dropzone { position: relative; border: 2px dashed var(--tm-border-strong); border-radius: var(--tm-radius); padding: 22px; text-align: center; transition: border-color .15s, background .15s; }
.tm-dropzone.dragover { border-color: var(--tm-primary); background: var(--tm-primary-soft); }
.tm-dropzone.has-files { padding-bottom: 8px; }
.tm-file-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.tm-dropzone .dz-prompt { pointer-events: none; color: var(--tm-text-muted); }
.tm-dropzone .dz-ic { font-size: 28px; display: block; margin-bottom: 6px; }
.tm-dropzone .dz-hint { font-size: 12px; margin-top: 4px; opacity: .8; }
.tm-file-list { list-style: none; margin: 12px 0 0; padding: 0; text-align: start; position: relative; z-index: 1; }
.tm-file-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; background: var(--tm-surface-2); border-radius: 8px; margin-bottom: 6px; font-size: 13px; }
.tm-file-list li .sz { color: var(--tm-text-muted); font-weight: 600; }

/* ---------- Tables (reusable data grid) ---------- */
.tm-table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tm-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.tm-table thead th { text-align: start; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--tm-text-muted); font-weight: 700; padding: 12px 16px; border-bottom: 1px solid var(--tm-border); background: var(--tm-surface-2); }
.tm-table tbody td { padding: 12px 16px; border-bottom: 1px solid var(--tm-border); color: var(--tm-text-2); }
.tm-table tbody tr { transition: background .12s; }
.tm-table tbody tr:hover { background: var(--tm-surface-2); }

/* ---------- Toast + dropdown ---------- */
.tm-toast { position: fixed; inset-block-end: 26px; inset-inline-start: 26px; z-index: 200; background: var(--tm-text); color: var(--tm-surface); padding: 14px 20px; border-radius: 12px; box-shadow: var(--tm-shadow-lg); font-weight: 600; animation: tm-rise .28s var(--tm-ease); max-width: 380px; }
@keyframes tm-rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.tm-dropdown { position: absolute; inset-block-start: 54px; inset-inline-end: 8px; width: 372px; max-height: 470px; overflow-y: auto; background: var(--tm-surface); border: 1px solid var(--tm-border); border-radius: var(--tm-radius); box-shadow: var(--tm-shadow-lg); z-index: 100; display: none; }
.tm-dropdown.open { display: block; animation: tm-rise .18s var(--tm-ease); }
.tm-dropdown > .hd { padding: 14px 18px; font-weight: 700; border-bottom: 1px solid var(--tm-border); position: sticky; top: 0; background: var(--tm-surface); }
.tm-noti { padding: 13px 18px; border-bottom: 1px solid var(--tm-border); }
.tm-noti:hover { background: var(--tm-surface-2); }
.tm-noti.unread { background: color-mix(in srgb, var(--tm-primary-soft) 40%, var(--tm-surface)); }
.tm-noti .t { font-weight: 700; font-size: 13px; }
.tm-noti .b { color: var(--tm-text-muted); font-size: 13px; margin-top: 2px; }

/* ---------- Auth ---------- */
.tm-auth { min-height: 100vh; display: grid; place-items: center; padding: 24px;
    background:
      radial-gradient(1200px 600px at 100% -10%, rgba(26,115,232,.18), transparent 60%),
      radial-gradient(900px 500px at -10% 110%, rgba(132,48,206,.14), transparent 55%),
      var(--tm-bg);
}
.tm-auth-card { width: 400px; max-width: 94vw; padding: 38px; border-radius: var(--tm-radius-lg); box-shadow: var(--tm-shadow-lg); }
.tm-auth-card h1 { margin: 0 0 4px; font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.tm-auth-card .sub { color: var(--tm-text-muted); margin-bottom: 26px; }

.tm-validation { color: var(--tm-danger); font-size: 13px; margin-top: 5px; display: block; }
.tm-empty { padding: 56px 24px; text-align: center; color: var(--tm-text-muted); }
.tm-empty .ico { font-size: 40px; opacity: .5; display: block; margin-bottom: 10px; }

/* mobile menu toggle (hidden on desktop) */
.tm-menu-btn { display: none; }
/* lock background scroll while the mobile off-canvas sidebar is open */
body.tm-noscroll { overflow: hidden; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
    .tm-dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
    .tm-menu-btn { display: grid; }
    .tm-body { grid-template-columns: 1fr; }
    /* Off-canvas mobile sidebar — direction-adaptive, no per-language hardcoding.
       Anchor with LOGICAL insets: inset-inline-start auto-flips to the left edge in
       LTR and the right edge in RTL, so the panel always rests on the correct edge
       without a direction-specific anchor rule.
       The slide-out uses translateX, which is PHYSICAL and does NOT flip in RTL.
       So the hidden offset lives in a variable whose SIGN flips for RTL, keeping the
       hide direction in agreement with the anchored edge (hide past the start edge
       in both directions; slide to 0 when open). Only ONE value differs per
       direction — the offset sign — and `transform` is declared on just .tm-sidebar
       and .tm-sidebar.open, so the open state always wins with no specificity tie. */
    .tm-sidebar {
        position: fixed; top: var(--tm-topbar-h); bottom: 0;
        inset-inline-start: 0; inset-inline-end: auto;
        width: 280px; max-width: 84vw; z-index: 60;
        --tm-sidebar-off: -105%;                            /* LTR: hide past the left edge  */
        transform: translateX(var(--tm-sidebar-off));
        transition: transform .25s var(--tm-ease); box-shadow: var(--tm-shadow-lg);
    }
    [dir="rtl"] .tm-sidebar { --tm-sidebar-off: 220%; }     /* RTL: hide past the right edge */
    .tm-sidebar.open { transform: translateX(0); }          /* shown: flush to the start edge */
    .tm-search { max-width: none; }
    .tm-row-from { width: 120px; }
    .tm-grid-3, .tm-grid-2 { grid-template-columns: 1fr; }
    .tm-stats { grid-template-columns: 1fr 1fr; gap: 12px; }
    .tm-content { padding: 16px; }
    .tm-scrim { position: fixed; inset: var(--tm-topbar-h) 0 0; background: rgba(0,0,0,.4); z-index: 55; display: none; }
    .tm-scrim.open { display: block; }
}

@media (max-width: 520px) {
    .tm-stats { grid-template-columns: 1fr; }
    .tm-row-snippet { display: none; }
    .tm-row-from { width: 110px; }
    .page-title { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
