/* ===== الألوان والمتغيرات ===== */
:root {
    color-scheme: light;
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-2: #f8fafb;
    --surface-3: #eef2f4;
    --border: #e3e8ec;
    --border-strong: #cfd7de;
    --text: #13202b;
    --text-2: #4d5b68;
    --text-3: #8592a0;
    --brand: #0f766e;
    --brand-hover: #0b5f58;
    --brand-soft: #e3f3f1;
    --brand-text: #0b5f58;
    --blue: #2563eb;
    --blue-soft: #e7eefd;
    --violet: #7c3aed;
    --violet-soft: #f0eafd;
    --green: #15803d;
    --green-soft: #e4f5ea;
    --amber: #b45309;
    --amber-soft: #fdf1e1;
    --red: #b42318;
    --red-soft: #fdecea;
    --wa: #128c4a;
    --shadow-sm: 0 1px 2px rgb(16 24 40 / 5%);
    --shadow: 0 1px 3px rgb(16 24 40 / 6%), 0 8px 24px rgb(16 24 40 / 5%);
    --shadow-lg: 0 24px 64px rgb(16 24 40 / 22%);
    --radius: 14px;
    --radius-sm: 10px;
    --sidebar: 264px;
    --font: "IBM Plex Sans Arabic", Tahoma, "Segoe UI", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --bg: #0e1318;
        --surface: #151b21;
        --surface-2: #1a2128;
        --surface-3: #212932;
        --border: #263039;
        --border-strong: #35414c;
        --text: #e6ebef;
        --text-2: #aab5bf;
        --text-3: #7a8692;
        --brand: #2bb3a5;
        --brand-hover: #3cc7b8;
        --brand-soft: rgb(43 179 165 / 14%);
        --brand-text: #5fd3c6;
        --blue: #6b9cff;
        --blue-soft: rgb(107 156 255 / 14%);
        --violet: #b08cff;
        --violet-soft: rgb(176 140 255 / 14%);
        --green: #4ccf7b;
        --green-soft: rgb(76 207 123 / 13%);
        --amber: #f0a64a;
        --amber-soft: rgb(240 166 74 / 13%);
        --red: #ff7b6e;
        --red-soft: rgb(255 123 110 / 13%);
        --wa: #3fcf7f;
        --shadow-sm: none;
        --shadow: 0 1px 2px rgb(0 0 0 / 30%);
        --shadow-lg: 0 24px 64px rgb(0 0 0 / 55%);
    }
}

/* ===== أساسيات ===== */
* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

a {
    color: var(--brand-text);
    text-decoration: none;
}

h1,
h2,
p {
    margin-top: 0;
}

.icon {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

[hidden] {
    display: none !important;
}

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

/* ===== التخطيط العام ===== */
.layout {
    min-height: 100vh;
}

.main {
    min-width: 0;
    margin-right: var(--sidebar);
    padding: 28px 32px 40px;
}

/* ===== الشريط الجانبي ===== */
.sidebar {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 30;
    display: flex;
    width: var(--sidebar);
    flex-direction: column;
    padding: 20px 14px 14px;
    border-left: 1px solid var(--border);
    background: var(--surface);
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 4px 8px 22px;
    color: var(--text);
}

.brand strong {
    display: block;
    font-size: 15px;
    line-height: 1.3;
}

.brand small {
    color: var(--text-3);
    font-size: 12px;
}

.brand-mark {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--brand), #14b8a6);
    color: #fff;
    box-shadow: 0 6px 16px rgb(15 118 110 / 28%);
}

.brand-mark .icon {
    width: 20px;
    height: 20px;
}

.side-nav {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

.side-label {
    margin: 14px 10px 6px;
    color: var(--text-3);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.side-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-weight: 500;
    transition: background-color 120ms ease, color 120ms ease;
}

.side-nav a span {
    flex: 1;
}

.side-nav a b {
    min-width: 26px;
    padding: 0 7px;
    border-radius: 20px;
    background: var(--surface-3);
    color: var(--text-3);
    font-size: 11px;
    font-weight: 600;
    text-align: center;
}

.side-nav a:hover {
    background: var(--surface-2);
    color: var(--text);
}

.side-nav a.active {
    background: var(--brand-soft);
    color: var(--brand-text);
    font-weight: 600;
}

.side-nav a.active b {
    background: var(--surface);
    color: var(--brand-text);
}

.side-nav a.has-alert b {
    background: var(--amber-soft);
    color: var(--amber);
}

.side-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    padding: 12px 8px 4px;
    border-top: 1px solid var(--border);
}

.side-user form {
    margin: 0;
}

.side-user-name {
    min-width: 0;
    flex: 1;
}

.side-user-name strong,
.side-user-name small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.side-user-name strong {
    font-size: 13px;
}

.side-user-name small {
    color: var(--text-3);
    font-size: 11px;
}

.sidebar-backdrop,
.mobile-topbar {
    display: none;
}

/* ===== رأس الصفحة ===== */
.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

.page-header h1 {
    margin-bottom: 2px;
    font-size: 26px;
    font-weight: 700;
    line-height: 1.3;
}

.subtitle {
    margin-bottom: 0;
    color: var(--text-2);
}

.header-actions,
.button-row,
.row-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== الأزرار ===== */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 40px;
    padding: 8px 15px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    cursor: pointer;
    font-weight: 600;
    white-space: nowrap;
    transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.button .icon {
    width: 17px;
    height: 17px;
}

.button-primary {
    background: var(--brand);
    color: #fff;
    box-shadow: 0 1px 2px rgb(15 118 110 / 25%);
}

.button-primary:hover {
    background: var(--brand-hover);
    color: #fff;
}

.button-secondary {
    border-color: var(--border-strong);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.button-secondary:hover {
    background: var(--surface-2);
}

.button-ghost {
    color: var(--text-2);
}

.button-ghost:hover {
    background: var(--surface-3);
    color: var(--text);
}

.icon-button {
    display: inline-grid;
    width: 34px;
    height: 34px;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 9px;
    background: none;
    color: var(--text-3);
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease;
}

.icon-button:hover {
    background: var(--surface-3);
    color: var(--text);
}

.icon-button-danger:hover {
    background: var(--red-soft);
    color: var(--red);
}

.link-button {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    color: var(--text-3);
    font-size: 13px;
    white-space: nowrap;
}

.link-button:hover {
    color: var(--red);
}

.link-button-brand,
.link-button-brand:hover {
    color: var(--brand-text);
    font-size: inherit;
}

.link-button .icon {
    width: 15px;
    height: 15px;
}

/* ===== التنبيهات ===== */
.notice {
    margin-bottom: 18px;
    padding: 12px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.notice p {
    margin: 0;
}

.notice p + p {
    margin-top: 4px;
}

.notice-success {
    border-color: color-mix(in srgb, var(--green) 25%, transparent);
    background: var(--green-soft);
    color: var(--green);
}

.notice-error {
    border-color: color-mix(in srgb, var(--red) 25%, transparent);
    background: var(--red-soft);
    color: var(--red);
}

/* ===== بطاقات الإحصاء ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    color: var(--text);
    transition: border-color 120ms ease, transform 120ms ease;
}

a.stat-card:hover {
    border-color: var(--border-strong);
    transform: translateY(-1px);
}

.stat-body {
    display: flex;
    min-width: 0;
    flex-direction: column;
}

.stat-body span {
    color: var(--text-2);
    font-size: 13px;
}

.stat-body strong {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.25;
}

.stat-icon {
    display: grid;
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 12px;
}

.stat-icon .icon {
    width: 21px;
    height: 21px;
}

.tone-brand { background: var(--brand-soft); color: var(--brand-text); }
.tone-blue { background: var(--blue-soft); color: var(--blue); }
.tone-violet { background: var(--violet-soft); color: var(--violet); }
.tone-green { background: var(--green-soft); color: var(--green); }
.tone-amber { background: var(--amber-soft); color: var(--amber); }

/* ===== البطاقة الرئيسية والأدوات ===== */
.card,
.panel {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.panel {
    margin-bottom: 20px;
    padding: 22px;
}

.panel-heading {
    margin-bottom: 16px;
}

.panel-heading h2 {
    margin: 0;
    font-size: 17px;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.search-box {
    position: relative;
    display: flex;
    min-width: 240px;
    flex: 1 1 320px;
    align-items: center;
}

.search-box .icon {
    position: absolute;
    right: 12px;
    color: var(--text-3);
    pointer-events: none;
}

.search-box input {
    padding-right: 38px !important;
}

.toolbar input,
.toolbar select,
.field input,
.field select,
.field textarea,
.inline-form input {
    width: 100%;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    outline: none;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.toolbar select {
    width: auto;
    min-width: 140px;
    max-width: 200px;
}

.toolbar input:focus,
.toolbar select:focus,
.field input:focus,
.field select:focus,
.field textarea:focus,
.inline-form input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}

.result-bar {
    padding: 10px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-3);
    font-size: 12px;
}

/* ===== الجدول ===== */
.table-wrap {
    position: relative;
    overflow-x: auto;
}

.data-table,
.users-table {
    width: 100%;
    border-collapse: collapse;
    text-align: right;
}

.data-table {
    min-width: 1050px;
}

.data-table th,
.users-table th {
    padding: 11px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-3);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.data-table td,
.users-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-2);
    font-size: 13px;
    vertical-align: top;
}

.data-table td > span,
.data-table td > .muted {
    display: block;
}

.data-table tbody tr:last-child td,
.users-table tbody tr:last-child td {
    border-bottom: 0;
}

.data-table tbody tr {
    transition: background-color 100ms ease;
}

.data-table tbody tr:hover {
    background: var(--surface-2);
}

.cell-name {
    min-width: 240px;
    max-width: 320px;
}

.name-cell {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.record-name {
    display: block;
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.45;
}

.record-name:hover {
    color: var(--brand-text);
}

.muted {
    color: var(--text-3);
    font-size: 12px;
}

.ltr {
    display: block;
    direction: ltr;
    text-align: right;
}

.clamp {
    display: -webkit-box !important;
    max-width: 200px;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.avatar {
    display: grid;
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 11px;
    background: var(--brand-soft);
    color: var(--brand-text);
    font-size: 15px;
    font-weight: 700;
}

.avatar .icon {
    width: 19px;
    height: 19px;
}

.avatar-institution {
    background: var(--blue-soft);
    color: var(--blue);
}

.avatar-person {
    border-radius: 50%;
    background: var(--violet-soft);
    color: var(--violet);
}

.avatar-sm {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    font-size: 14px;
}

.tag {
    display: inline-block !important;
    margin-bottom: 4px;
    padding: 2px 9px;
    border-radius: 6px;
    background: var(--surface-3);
    color: var(--text);
    font-size: 12px;
    font-weight: 500;
}

.contact-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.contact-list a,
.contact-list > span {
    display: inline-flex;
    max-width: 230px;
    align-items: center;
    gap: 6px;
    color: var(--text-2);
    font-size: 12.5px;
}

.contact-list a span,
.contact-list > span span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.contact-list .icon {
    width: 15px;
    height: 15px;
    color: var(--text-3);
}

.contact-list a:hover {
    color: var(--brand-text);
}

.contact-list a:hover .icon {
    color: var(--brand-text);
}

.contact-list .wa,
.contact-list .wa .icon {
    color: var(--wa);
}

.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.status-chip::before {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    content: "";
}

.status-positive { background: var(--green-soft); color: var(--green); }
.status-progress { background: var(--amber-soft); color: var(--amber); }
.status-muted { background: var(--red-soft); color: var(--red); }
.status-neutral { background: var(--surface-3); color: var(--text-2); }

.follow-up {
    display: inline-flex !important;
    align-items: center;
    gap: 5px;
    margin-top: 6px;
    color: var(--text-3);
    font-size: 12px;
}

.follow-up .icon {
    width: 14px;
    height: 14px;
}

.follow-up.overdue {
    color: var(--amber);
    font-weight: 600;
}

.cell-actions {
    width: 90px;
}

.row-actions {
    justify-content: flex-end;
    gap: 2px;
}

.delete-form {
    margin: 0;
}

.empty-row td {
    padding: 0;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 56px 16px;
    color: var(--text-2);
    text-align: center;
}

.empty-state strong {
    margin-top: 6px;
    color: var(--text);
    font-size: 15px;
}

.empty-state p {
    margin: 0;
    font-size: 13px;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    color: var(--text-3);
    font-size: 13px;
}

/* ===== النوافذ المنبثقة ===== */
dialog {
    padding: 0;
    border: 0;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-lg);
}

dialog::backdrop {
    background: rgb(10 18 26 / 45%);
    backdrop-filter: blur(2px);
}

dialog > form {
    display: flex;
    max-height: inherit;
    flex-direction: column;
}

.drawer {
    width: min(720px, 100vw);
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    margin: 0 0 0 auto;
    border-radius: 0;
}

.drawer[open] {
    animation: drawer-in 220ms ease-out;
}

.drawer > form {
    height: 100%;
}

.modal {
    width: min(520px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    border-radius: 18px;
}

.modal[open] {
    animation: modal-in 180ms ease-out;
}

@keyframes drawer-in {
    from { transform: translateX(40px); opacity: 0; }
}

@keyframes modal-in {
    from { transform: translateY(12px) scale(0.98); opacity: 0; }
}

.drawer-header,
.drawer-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 22px;
}

.drawer-header {
    border-bottom: 1px solid var(--border);
}

.drawer-header h2 {
    margin: 0;
    font-size: 18px;
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 22px;
}

.drawer-body > .field {
    margin-top: 16px;
}

.drawer-footer {
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}

.drawer-footer p {
    margin: 0;
    color: var(--text-3);
    font-size: 12px;
}

.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin: 0 0 20px;
    padding: 4px;
    border: 0;
    border-radius: 12px;
    background: var(--surface-3);
}

.segmented label {
    cursor: pointer;
}

.segmented input {
    position: absolute;
    opacity: 0;
}

.segmented span {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px;
    border-radius: 9px;
    color: var(--text-2);
    font-weight: 600;
    transition: background-color 120ms ease, color 120ms ease;
}

.segmented input:checked + span {
    background: var(--surface);
    color: var(--brand-text);
    box-shadow: var(--shadow-sm), 0 0 0 1px var(--border);
}

.segmented input:focus-visible + span {
    outline: 2px solid var(--brand);
}

.form-section {
    margin: 0 0 22px;
    padding: 0;
    border: 0;
}

.form-section legend {
    width: 100%;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.field {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 6px;
    color: var(--text-2);
    font-size: 13px;
    font-weight: 500;
}

.field-wide {
    grid-column: 1 / -1;
}

.field textarea {
    min-height: 70px;
    resize: vertical;
}

.dropzone {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 28px 16px;
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface-2);
    cursor: pointer;
    text-align: center;
    transition: border-color 120ms ease, background-color 120ms ease;
}

.dropzone:hover,
.dropzone.has-file {
    border-color: var(--brand);
    background: var(--brand-soft);
}

.dropzone strong {
    margin-top: 6px;
    overflow-wrap: anywhere;
}

.dropzone small {
    color: var(--text-3);
}

.dropzone input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.help-text {
    margin: 14px 0 0;
    color: var(--text-3);
    font-size: 12px;
    line-height: 1.7;
}

/* ===== حالة المواعيد ===== */
.tone-red { background: var(--red-soft); color: var(--red); }

.follow-up.due-overdue,
.due-badge.due-overdue,
.task-group-title.due-overdue {
    color: var(--red);
}

.follow-up.due-today,
.due-badge.due-today,
.task-group-title.due-today {
    color: var(--amber);
}

.follow-up.due-overdue,
.follow-up.due-today {
    font-weight: 600;
}

/* ===== صفحة السجل ===== */
.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    color: var(--text-3);
    font-size: 13px;
}

.breadcrumb a {
    color: var(--text-2);
}

.breadcrumb a:hover {
    color: var(--brand-text);
}

.profile {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 20px;
    padding: 22px;
}

.profile-main {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 16px;
}

.profile-text h1 {
    margin: 0;
    font-size: 24px;
    line-height: 1.35;
}

.profile-text .muted {
    margin: 2px 0 0;
}

.profile-tags {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
}

.profile-tags .tag {
    margin: 0;
}

.tag-plain {
    display: inline-flex !important;
    align-items: center;
    gap: 4px;
    background: none;
    color: var(--text-2);
}

.tag-plain .icon {
    width: 14px;
    height: 14px;
}

.avatar-lg {
    width: 60px;
    height: 60px;
    border-radius: 16px;
    font-size: 24px;
}

.avatar-lg.avatar-person {
    border-radius: 50%;
}

.avatar-lg .icon {
    width: 28px;
    height: 28px;
}

.kind-pill {
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.kind-pill-institution { background: var(--blue-soft); color: var(--blue); }
.kind-pill-person { background: var(--violet-soft); color: var(--violet); }

.profile-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.profile-actions form {
    margin: 0;
}

.button-wa {
    color: var(--wa);
}

.button-sm {
    min-height: 34px;
    padding: 5px 12px;
    font-size: 13px;
}

.contact-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    align-items: start;
    gap: 20px;
}

.contact-main,
.contact-side {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.card-header h2 {
    margin: 0;
    font-size: 16px;
}

.card-body {
    padding: 18px 20px;
}

.log-form {
    padding: 18px 20px 20px;
}

.channel-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}

.channel-picker label {
    cursor: pointer;
}

.channel-picker input {
    position: absolute;
    opacity: 0;
}

.channel-picker span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 20px;
    color: var(--text-2);
    font-size: 13px;
    font-weight: 500;
    transition: all 120ms ease;
}

.channel-picker .icon {
    width: 15px;
    height: 15px;
}

.channel-picker input:checked + span {
    border-color: var(--brand);
    background: var(--brand-soft);
    color: var(--brand-text);
}

.channel-picker input:focus-visible + span {
    outline: 2px solid var(--brand);
}

.next-step {
    margin: 18px 0 0;
    padding: 14px 16px 16px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.next-step legend {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 6px;
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}

.next-step legend small {
    color: var(--text-3);
    font-weight: 400;
}

.next-step legend .icon {
    width: 16px;
    height: 16px;
    color: var(--brand-text);
}

.quick-dates {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.chip-button {
    padding: 4px 11px;
    border: 1px solid var(--border-strong);
    border-radius: 20px;
    background: var(--surface);
    color: var(--text-2);
    cursor: pointer;
    font-size: 12px;
}

.chip-button:hover,
.chip-button.active {
    border-color: var(--brand);
    color: var(--brand-text);
}

.chip-button.active {
    background: var(--brand-soft);
}

.log-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 16px;
}

.timeline {
    margin: 0;
    padding: 8px 20px 4px;
    list-style: none;
}

.timeline-item {
    position: relative;
    display: flex;
    gap: 14px;
    padding: 12px 0 16px;
}

.timeline-item::before {
    position: absolute;
    top: 48px;
    right: 17px;
    bottom: -6px;
    width: 2px;
    background: var(--border);
    content: "";
}

.timeline-item:last-child::before {
    display: none;
}

.timeline-icon {
    position: relative;
    display: grid;
    width: 36px;
    height: 36px;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--brand-text);
}

.timeline-icon .icon {
    width: 17px;
    height: 17px;
}

.timeline-start .timeline-icon {
    background: var(--surface-3);
    color: var(--text-3);
}

.timeline-body {
    min-width: 0;
    flex: 1;
    padding-top: 6px;
}

.timeline-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
}

.timeline-head strong {
    font-size: 14px;
}

.timeline-head .record-name {
    display: inline;
}

.timeline-delete {
    margin: -6px auto 0 0;
    opacity: 0;
    transition: opacity 120ms ease;
}

.timeline-item:hover .timeline-delete,
.timeline-delete:focus-within {
    opacity: 1;
}

.timeline-summary {
    margin: 6px 0 0;
    color: var(--text-2);
    font-size: 13.5px;
    line-height: 1.75;
}

.timeline-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.timeline-meta span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 7px;
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 12px;
}

.timeline-meta .icon {
    width: 14px;
    height: 14px;
}

.timeline-wide {
    padding: 8px 22px;
}

.next-card {
    border-top: 3px solid var(--border-strong);
}

.next-card.due-overdue { border-top-color: var(--red); }
.next-card.due-today { border-top-color: var(--amber); }
.next-card.due-upcoming { border-top-color: var(--brand); }

.next-when {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
    margin: 0;
}

.next-when .icon {
    color: var(--text-3);
}

.next-when strong {
    font-size: 18px;
}

.next-when span {
    color: var(--text-3);
    font-size: 13px;
}

.due-overdue .next-when strong,
.due-overdue .next-when .icon { color: var(--red); }
.due-today .next-when strong,
.due-today .next-when .icon { color: var(--amber); }

.next-what {
    margin: 8px 0 16px;
    color: var(--text);
    font-size: 15px;
    font-weight: 500;
}

.next-buttons {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.next-buttons form {
    margin: 0;
}

.postpone-form {
    margin: 0;
}

.postpone-form select {
    min-height: 34px;
    padding: 4px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-2);
    cursor: pointer;
    font-size: 13px;
}

.next-buttons .postpone-form select {
    min-height: 40px;
}

.set-followup {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 12px;
}

.details {
    margin: 0;
    padding: 6px 20px 14px;
}

.details div {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.details div:last-child {
    border-bottom: 0;
}

.details dt {
    margin-bottom: 2px;
    color: var(--text-3);
    font-size: 12px;
}

.details dd {
    margin: 0;
    color: var(--text);
    font-size: 13.5px;
    overflow-wrap: anywhere;
}

.details dd[dir="ltr"] {
    text-align: right;
}

/* ===== صفحة المتابعات ===== */
.stats-grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.tabs-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
}

.tabs {
    display: flex;
    gap: 4px;
}

.tabs a {
    margin-bottom: -1px;
    padding: 14px 12px 12px;
    border-bottom: 2px solid transparent;
    color: var(--text-2);
    font-weight: 600;
}

.tabs a b {
    margin-right: 4px;
    padding: 0 7px;
    border-radius: 10px;
    background: var(--surface-3);
    font-size: 11px;
}

.tabs a.active {
    border-bottom-color: var(--brand);
    color: var(--brand-text);
}

.segmented-links {
    display: flex;
    gap: 2px;
    margin: 8px 0;
    padding: 3px;
    border-radius: 10px;
    background: var(--surface-3);
}

.segmented-links a {
    padding: 4px 12px;
    border-radius: 8px;
    color: var(--text-2);
    font-size: 13px;
}

.segmented-links a.active {
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

.task-group {
    padding: 4px 0 8px;
}

.task-group + .task-group {
    border-top: 1px solid var(--border);
}

.task-group-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 16px 20px 6px;
    color: var(--brand-text);
    font-size: 14px;
}

.task-group-title b {
    padding: 0 8px;
    border-radius: 10px;
    background: var(--surface-3);
    color: var(--text-2);
    font-size: 11px;
}

.task-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.task {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 20px;
    transition: background-color 100ms ease;
}

.task:hover {
    background: var(--surface-2);
}

.task-main {
    min-width: 0;
    flex: 1;
}

.task-main p {
    margin: 0;
}

.task-action {
    color: var(--text);
    font-size: 13.5px;
}

.due-badge {
    flex: 0 0 auto;
    padding: 3px 10px;
    border-radius: 20px;
    background: var(--surface-3);
    color: var(--text-2);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.due-badge.due-overdue { background: var(--red-soft); }
.due-badge.due-today { background: var(--amber-soft); }

.task-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 4px;
}

.icon-wa {
    color: var(--wa);
}

/* ===== صفحة الحساب ===== */
.users-table {
    min-width: 720px;
}

.ltr-cell {
    text-align: left;
}

.inline-form {
    display: flex;
    gap: 6px;
    margin: 0;
}

.inline-form input {
    width: 170px;
    min-height: 34px;
    padding: 5px 10px;
    font-size: 13px;
}

.form-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 18px;
}

.form-footer p {
    margin: 0;
    color: var(--text-3);
    font-size: 12px;
}

.panel .form-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* ===== صفحة الدخول ===== */
.auth-shell {
    display: grid;
    min-height: 100vh;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
}

.auth-side {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    padding: 48px;
    background: linear-gradient(150deg, #0b5f58, #0f766e 45%, #14b8a6);
    color: #fff;
}

.auth-side::after {
    position: absolute;
    inset: auto -120px -160px auto;
    width: 420px;
    height: 420px;
    border: 60px solid rgb(255 255 255 / 7%);
    border-radius: 50%;
    content: "";
}

.auth-side .brand {
    padding: 0;
    color: #fff;
}

.auth-side .brand small {
    color: rgb(255 255 255 / 70%);
}

.auth-side .brand-mark {
    background: rgb(255 255 255 / 16%);
    box-shadow: none;
}

.auth-side h2 {
    max-width: 420px;
    margin-bottom: 12px;
    font-size: 30px;
    line-height: 1.4;
}

.auth-side p {
    max-width: 400px;
    margin: 0;
    color: rgb(255 255 255 / 80%);
    font-size: 15px;
}

.auth-features {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 22px;
}

.auth-features span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    background: rgb(255 255 255 / 12%);
    font-size: 13px;
}

.auth-features .icon {
    width: 15px;
    height: 15px;
}

.auth-main {
    display: grid;
    place-items: center;
    padding: 32px 20px;
}

.auth-card {
    width: min(400px, 100%);
}

.auth-card h1 {
    margin-bottom: 6px;
    font-size: 26px;
}

.auth-card .subtitle {
    margin-bottom: 4px;
}

.auth-error {
    margin: 18px 0 0;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 24px;
}

.auth-form .field input {
    min-height: 44px;
}

.auth-form .button {
    min-height: 46px;
    margin-top: 6px;
}

/* ===== الشاشات المتوسطة ===== */
@media (max-width: 1280px) {
    .stat-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .stat-icon {
        width: 38px;
        height: 38px;
    }

    .page-header {
        flex-wrap: wrap;
    }

    .header-actions {
        flex-wrap: wrap;
    }
}

/* الجدول يتحول إلى بطاقات عندما تضيق المساحة */
@media (max-width: 1100px) {
    .contact-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .contact-side {
        order: -1;
    }

    .task {
        flex-wrap: wrap;
    }

    .task-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .data-table {
        min-width: 0;
    }

    .data-table thead {
        display: none;
    }

    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
    }

    .data-table tr {
        position: relative;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0 24px;
        padding: 14px 18px;
        border-bottom: 1px solid var(--border);
    }

    .data-table td.cell-name {
        grid-column: 1 / -1;
    }

    .data-table tbody tr:last-child {
        border-bottom: 0;
    }

    .data-table td {
        display: grid;
        grid-template-columns: 84px minmax(0, 1fr);
        gap: 2px 10px;
        justify-items: start;
        align-content: start;
        max-width: none;
        padding: 4px 0;
        border: 0;
    }

    .data-table td::before {
        grid-row: span 3;
        color: var(--text-3);
        content: attr(data-label);
        font-size: 12px;
    }

    .data-table td.cell-name {
        display: block;
        max-width: none;
        margin-bottom: 6px;
        padding-left: 76px;
    }

    .data-table td.cell-name::before,
    .data-table td.cell-actions::before {
        display: none;
    }

    .data-table td.cell-actions {
        position: absolute;
        top: 12px;
        left: 12px;
        width: auto;
        padding: 0;
    }

    .empty-row td {
        display: block;
    }

    .empty-row td::before {
        display: none;
    }

    .clamp {
        max-width: 100%;
    }
}

/* ===== الشاشات الصغيرة: قائمة منزلقة وبطاقات بدل الجدول ===== */
@media (max-width: 960px) {
    .main {
        margin-right: 0;
        padding: 0 16px 32px;
    }

    .sidebar {
        transform: translateX(100%);
        box-shadow: var(--shadow-lg);
        transition: transform 200ms ease;
    }

    .sidebar-open .sidebar {
        transform: none;
    }

    .sidebar-open .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 25;
        display: block;
        background: rgb(10 18 26 / 40%);
    }

    .mobile-topbar {
        position: sticky;
        top: 0;
        z-index: 20;
        display: flex;
        align-items: center;
        gap: 8px;
        margin: 0 -16px 18px;
        padding: 10px 12px;
        border-bottom: 1px solid var(--border);
        background: color-mix(in srgb, var(--surface) 92%, transparent);
        backdrop-filter: blur(8px);
    }

    .brand-compact {
        padding: 0;
        font-size: 14px;
    }

    .brand-compact .brand-mark {
        width: 30px;
        height: 30px;
        border-radius: 9px;
    }

    .brand-compact .brand-mark .icon {
        width: 16px;
        height: 16px;
    }

    .panel .form-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .auth-shell {
        grid-template-columns: 1fr;
    }

    .auth-side {
        padding: 28px 24px;
    }

    .auth-side h2,
    .auth-side p,
    .auth-features {
        display: none;
    }
}

@media (max-width: 700px) {
    .page-header h1 {
        font-size: 22px;
    }

    .header-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .header-actions .button-primary,
    .header-actions .button-secondary {
        grid-row: 1;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .stats-grid:not(.stats-grid-4) > :first-child {
        grid-column: 1 / -1;
    }

    .stats-grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .profile {
        padding: 16px;
    }

    .profile-actions {
        width: 100%;
    }

    .avatar-lg {
        width: 48px;
        height: 48px;
    }

    .profile-text h1 {
        font-size: 20px;
    }

    .task {
        padding: 12px 16px;
    }

    .task .avatar {
        display: none;
    }

    .timeline,
    .timeline-wide {
        padding-right: 14px;
        padding-left: 14px;
    }

    .timeline-delete {
        opacity: 1;
    }

    .stat-card {
        flex-direction: row;
        align-items: center;
        padding: 11px 12px;
        gap: 10px;
    }

    .stat-icon {
        width: 34px;
        height: 34px;
        border-radius: 10px;
    }

    .stat-icon .icon {
        width: 18px;
        height: 18px;
    }

    .stat-body span {
        font-size: 12px;
    }

    .stat-body strong {
        font-size: 19px;
    }

    .toolbar select {
        min-width: 0;
        max-width: none;
        flex: 1 1 calc(50% - 4px);
    }

    .search-box {
        min-width: 100%;
    }

    .toolbar > .button {
        flex: 1;
    }

    .data-table tr {
        grid-template-columns: minmax(0, 1fr);
        padding: 14px 16px;
    }

    .data-table td {
        grid-template-columns: 90px minmax(0, 1fr);
    }

    .contact-list a,
    .contact-list > span {
        max-width: 100%;
    }

    .drawer {
        width: 100vw;
    }

    .form-grid,
    .panel .form-grid {
        grid-template-columns: 1fr;
    }

    .drawer-header,
    .drawer-footer,
    .drawer-body {
        padding-right: 16px;
        padding-left: 16px;
    }

    .drawer-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .drawer-footer .button-row .button {
        flex: 1;
    }

    .form-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .panel {
        padding: 16px;
    }

    .inline-form input {
        width: 130px;
    }
}
