:root {
    color-scheme: light;
    --bg: #f5f7fb;
    --card: #ffffff;
    --border: #d9e0ec;
    --text: #172033;
    --muted: #68758f;
    --primary: #274690;
    --primary-dark: #1d356e;
    --danger: #b42318;
    --success: #027a48;
    --warning: #b54708;
}

* {
    box-sizing: border-box;
}

html {
    direction: rtl;
}

body {
    margin: 0;
    font-family: Arial, "Noto Sans Hebrew", sans-serif;
    background: var(--bg);
    color: var(--text);
    text-align: right;
}

/* ─── Tab navigation ──────────────────────── */

.tab-nav {
    display: flex;
    gap: 0;
    background: #101828;
    padding: 0 20px;
    border-bottom: 2px solid rgba(255,255,255,0.08);
}

.tab {
    display: inline-flex;
    align-items: center;
    padding: 14px 24px;
    color: #98a2b3;
    text-decoration: none;
    font-size: 15px;
    font-weight: 600;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
    color: #d0d5dd;
}

.tab-active {
    color: #fff;
    border-bottom-color: var(--primary);
}

.shell {
    display: grid;
    /* RTL: first column (sidebar) on the right; second (content) fills the rest */
    grid-template-columns: 240px minmax(0, 1fr);
    grid-template-areas: "sidebar content";
    min-height: 100vh;
}

.shell > .sidebar {
    grid-area: sidebar;
}

.shell > .content {
    grid-area: content;
    min-width: 0;
}

/* Safety: if aside is missing, content must span full width (avoids 240px crush) */
.shell > .content:only-child {
    grid-column: 1 / -1;
    grid-area: auto;
}

.sidebar {
    background: #101828;
    color: #fff;
    padding: 32px 20px;
}

.sidebar h1 {
    margin: 0 0 24px;
    font-size: 28px;
}

.sidebar nav {
    display: grid;
    gap: 4px;
}

.sidebar-section {
    margin-bottom: 24px;
}

.sidebar-section-title {
    font-size: 12px;
    color: #98a2b3;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    padding: 0 12px;
}

.sidebar a {
    color: #d0d5dd;
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 10px;
}

.sidebar a:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.sidebar a.active {
    background: rgba(255,255,255,0.12);
    color: #fff;
    font-weight: 600;
}

.content {
    min-width: 0;
    padding: 32px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.page-header h2 {
    margin: 0 0 6px;
}

.page-header p {
    margin: 0;
    color: var(--muted);
}

.card,
.stat-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(16, 24, 40, 0.04);
}

.card {
    min-width: 0;
    padding: 20px;
}

.form-sidebar {
    background: #fafbfd;
    border-color: #e2e8f0;
    position: sticky;
    top: 20px;
    align-self: start;
}

.form-sidebar h3 {
    margin: 0 0 16px;
    font-size: 16px;
    color: var(--muted);
    text-transform: none;
    letter-spacing: normal;
}

.form-sidebar .stack-form {
    gap: 12px;
}

.form-sidebar label span {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
}

.card-grid,
.split-layout {
    display: grid;
    gap: 20px;
    min-width: 0;
}

.card-grid {
    grid-template-columns: 1.1fr 0.9fr;
}

.split-layout {
    grid-template-columns: 340px 1fr;
}

.form-card,
.narrow-card {
    max-width: 100%;
}

.narrow-card {
    width: 640px;
}

.stack-form {
    display: grid;
    gap: 14px;
}

.stack-form label,
.filters-inline > label {
    display: grid;
    gap: 8px;
    font-weight: 600;
}

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

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 11px 12px;
    background: #fff;
    color: var(--text);
    text-align: right;
}

button,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 10px;
    padding: 11px 16px;
    background: var(--primary);
    color: #fff;
    text-decoration: none;
    cursor: pointer;
}

button:hover,
.button:hover {
    background: var(--primary-dark);
}

.button.secondary {
    background: #e7ecf7;
    color: var(--text);
}

.button.danger,
button.danger {
    background: var(--danger, #dc2626);
}

.button.danger:hover,
button.danger:hover {
    background: #b91c1c;
}

.page-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.notes-card-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 16px;
}

.notes-card-item {
    position: relative;
    min-width: 0;
}

.notes-card-item .notes-drag-handle {
    top: 8px;
    right: 8px;
    left: auto;
    padding: 4px 6px;
    font-size: 14px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--border);
}

.notes-card-item .notes-card {
    padding-top: 34px;
}

.notes-card-link {
    text-decoration: none;
    color: inherit;
    min-width: 0;
}

.notes-card {
    height: 100%;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.notes-card-link:hover .notes-card {
    border-color: #c7d2fe;
    box-shadow: 0 12px 28px rgba(16, 24, 40, 0.08);
}

.notes-card-title {
    margin: 0 0 10px;
    font-size: 1.05rem;
    font-weight: 600;
}

.notes-card-client {
    margin-bottom: 10px;
}

.notes-card-client-name {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.3;
    color: var(--text);
}

.notes-card-client-module {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    font-weight: 600;
    color: #3730a3;
}

.notes-card-date {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.notes-empty {
    text-align: center;
    display: grid;
    gap: 16px;
    justify-items: center;
}

.notes-detail-header {
    align-items: flex-start;
}

.notes-back-link {
    display: inline-block;
    margin-bottom: 8px;
    color: var(--muted);
    text-decoration: none;
    font-size: 14px;
}

.notes-back-link:hover {
    color: var(--primary);
}

.notes-detail-form {
    display: grid;
    gap: 20px;
}

.notes-intro-textarea {
    min-height: 180px;
    resize: vertical;
}

.notes-accordion {
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 12px;
    background: #fafbfd;
}

.notes-accordion-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    list-style: none;
}

.notes-accordion-summary::-webkit-details-marker {
    display: none;
}

.notes-accordion-label {
    font-weight: 600;
}

.notes-accordion-body {
    padding: 0 16px 16px;
}

.notes-add-section {
    margin-top: 8px;
}

.notes-save-actions {
    position: sticky;
    bottom: 16px;
    background: rgba(243, 244, 246, 0.92);
    padding: 12px 0;
    z-index: 2;
}

.stack-form label.checkbox-line {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    width: 100%;
}

.checkbox-line input,
.stack-form label.checkbox-line input {
    width: auto;
    margin: 0;
    flex: 0 0 auto;
}

.stack-form label.checkbox-line span {
    display: inline;
}

.clients-filter-form {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 16px;
}

.clients-filter-form .checkbox-line {
    font-weight: 600;
}

.filters-inline {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.status-filter-field {
    position: relative;
    display: grid;
    gap: 8px;
    font-weight: 600;
    min-width: 200px;
}

.status-filter-field > span {
    font-weight: 600;
}

.status-filter-dropdown {
    position: relative;
}

.status-filter-toggle {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 11px 12px;
    background: #fff;
    color: var(--text);
    text-align: right;
    font: inherit;
    font-weight: 400;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.status-filter-toggle:hover {
    background: #fff;
    border-color: #bcc6d8;
}

.status-filter-dropdown.is-open .status-filter-toggle {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(39, 70, 144, 0.12);
}

.status-filter-toggle::after {
    content: "▾";
    color: var(--muted);
    font-size: 12px;
    flex-shrink: 0;
}

.status-filter-panel {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 100%;
    width: max-content;
    z-index: 30;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px;
    box-shadow: 0 8px 24px rgba(16, 24, 40, 0.12);
    gap: 4px;
}

.status-filter-dropdown.is-open .status-filter-panel {
    display: grid;
}

.status-filter-option {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    margin: 0;
    white-space: nowrap;
}

.status-filter-option:hover {
    background: #f5f7fb;
}

.status-filter-option input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    padding: 0;
    flex: 0 0 16px;
}

.status-filter-option .status-badge {
    cursor: pointer;
}

.filters-inline > * {
    min-width: 160px;
}

.stats-inline {
    display: flex;
    gap: 12px;
}

.stat-box {
    min-width: 150px;
    padding: 18px;
    display: grid;
    gap: 6px;
}

.stat-box strong {
    font-size: 24px;
}

.stat-box span {
    color: var(--muted);
}

.compact {
    min-width: 200px;
}

.flash-stack {
    display: grid;
    gap: 10px;
    margin-bottom: 16px;
}

.flash {
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #fff;
}

.flash-success {
    border-color: #9ee2b8;
    color: var(--success);
}

.flash-danger {
    border-color: #f5b8b2;
    color: var(--danger);
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

th,
td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    text-align: right;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 14px;
}

.entry-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 14px;
}

.entry-list li {
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
}

.entry-list li:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.entry-list span,
.entry-list p {
    color: var(--muted);
}

.action-row,
.button-row {
    display: flex;
    gap: 12px;
    align-items: center;
}

.link-button {
    background: transparent;
    color: var(--danger);
    padding: 0;
}

.report-card {
    margin-bottom: 20px;
}

.report-head {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 18px;
}

.report-head h3 {
    margin: 0 0 4px;
}

.report-head p {
    margin: 0;
    color: var(--muted);
}

.report-totals {
    text-align: left;
    display: grid;
    gap: 4px;
}

/* ─── Tasks ─────────────────────────────── */

.task-row td {
    vertical-align: middle;
}

.task-row.task-overdue {
    background: #fef2f2;
    border-right: 3px solid var(--danger);
}

.task-row.task-due-soon {
    background: #fffbeb;
    border-right: 3px solid var(--warning);
}

.task-title {
    font-weight: 600;
}

.task-desc {
    font-size: 13px;
    color: var(--muted);
    margin-top: 2px;
}

.task-deadline .deadline-overdue {
    color: var(--danger);
    font-weight: 600;
}

.task-deadline .deadline-soon {
    color: var(--warning);
    font-weight: 600;
}

.no-deadline {
    color: var(--muted);
}

.empty-state {
    color: var(--muted);
    padding: 24px 0;
    text-align: center;
}

/* ─── Status badges / select ─────────────── */

.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.status-select {
    padding: 4px 8px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    width: auto;
    min-width: 130px;
}

.status-מחכה-לביצוע {
    background: #fef3c7;
    color: #92400e;
    border-color: #fcd34d;
}

.status-בביצוע {
    background: #dbeafe;
    color: #1e40af;
    border-color: #93c5fd;
}

.status-הושלם {
    background: #d1fae5;
    color: #065f46;
    border-color: #6ee7b7;
}

.status-הוקפא {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fca5a5;
}

.report-head p .status-badge {
    margin-inline-end: 6px;
    margin-bottom: 4px;
}

.task-list-overdue strong {
    color: var(--danger);
}

.filter-card {
    margin-bottom: 20px;
}

/* ─── Inline status form ────────────────── */

.status-form-inline {
    display: inline-block;
}

/* ─── Dashboard widgets ─────────────────── */

.dashboard-widgets {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.dashboard-widgets .card {
    padding: 24px;
}

.dashboard-widgets h3 {
    margin: 0 0 12px;
    font-size: 16px;
    color: var(--muted);
}

.widget-stat {
    font-size: 32px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

.widget-sub {
    color: var(--muted);
    font-size: 14px;
    margin: 4px 0 0;
}

.widget-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 8px;
}

.widget-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.widget-list li:last-child {
    border-bottom: 0;
}

.widget-link {
    font-size: 14px;
    color: var(--primary);
    text-decoration: none;
}

.widget-link:hover {
    text-decoration: underline;
}

/* ─── Drag-and-drop section reordering ───── */

.sortable-section {
    position: relative;
}

.drag-handle {
    position: absolute;
    top: 12px;
    right: 12px;
    cursor: grab;
    padding: 6px 8px;
    border-radius: 6px;
    color: var(--muted);
    font-size: 18px;
    line-height: 1;
    user-select: none;
    transition: background 0.15s, color 0.15s;
    z-index: 2;
}

.drag-handle:hover {
    background: #e7ecf7;
    color: var(--text);
}

.drag-handle:active {
    cursor: grabbing;
}

.drag-icon {
    display: block;
    letter-spacing: 2px;
}

.sortable-ghost {
    opacity: 0.4;
    background: #e7ecf7;
    border: 2px dashed var(--primary);
}

.sortable-drag {
    box-shadow: 0 10px 30px rgba(16, 24, 40, 0.15);
    transform: rotate(1deg);
    background: var(--card);
    z-index: 1000;
}

/* Offset section heading to make room for drag handle */
.sortable-section > h3 {
    padding-right: 40px;
}

/* ─── Markdown formatting toolbar ───── */

.toolbar-mini {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px 12px;
    font-size: 13px;
    font-family: inherit;
    background: #f0f2f5;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.toolbar-btn:hover {
    background: #d9e0ec;
    border-color: #b0bdd0;
}

.toolbar-btn:active {
    background: #c4cddb;
}

.toolbar-preview {
    background: #e7ecf7;
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
}

.toolbar-preview:hover {
    background: #d0d8f0;
}

.md-preview {
    min-height: 100px;
    padding: 14px;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: 8px;
    line-height: 1.4;
    font-size: 14px;
    white-space: normal;
    overflow-wrap: break-word;
}

.md-preview h2 {
    font-size: 18px;
    margin: 12px 0 8px;
    color: var(--text);
    line-height: 1.2;
}

.md-preview h3 {
    font-size: 16px;
    margin: 10px 0 6px;
    color: var(--text);
    line-height: 1.2;
}

.md-preview p {
    margin: 0 0 10px;
    line-height: 1.4;
}

.md-preview ul {
    margin: 0 0 10px;
    padding-right: 20px;
}

.md-preview li {
    margin-bottom: 4px;
    line-height: 1.4;
}

.md-preview strong {
    font-weight: 700;
}

.md-preview u {
    text-decoration: underline;
}

@media (max-width: 980px) {
    .tab-nav {
        padding: 0 12px;
    }

    .tab {
        padding: 12px 16px;
        font-size: 14px;
    }

    .shell,
    .card-grid,
    .split-layout,
    .notes-card-grid {
        grid-template-columns: 1fr;
    }

    .sidebar {
        padding-bottom: 16px;
    }

    .content {
        padding: 20px;
    }

    .page-header,
    .report-head {
        flex-direction: column;
        align-items: stretch;
    }

    .stats-inline,
    .button-row,
    .action-row {
        flex-wrap: wrap;
    }

    .filters-inline {
        flex-direction: column;
    }

    .filters-inline > * {
        min-width: 100%;
    }

    .dashboard-widgets {
        grid-template-columns: 1fr;
    }

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

/* ─── Hosting billing status ───────────────── */

.hosting-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.billing-overdue {
    color: #b42318;
    font-weight: 600;
}

.billing-soon {
    color: #b45309;
    font-weight: 600;
}

.billing-overdue-row {
    background: #fef3f2;
}

.billing-soon-row {
    background: #fffbeb;
}

.billing-action-required {
    background: #fff7ed;
    outline: 1px solid #fdba74;
}

.hosting-cancelled {
    opacity: 0.65;
}

.hosting-cancelled-section h3 {
    color: var(--muted);
}

.hosting-actions-cell {
    white-space: nowrap;
}

.hosting-actions-cell form {
    margin-left: 6px;
}

.btn-renew {
    background: #059669;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 13px;
    cursor: pointer;
}

.btn-renew:hover {
    background: #047857;
}

.btn-cancel-hosting {
    background: #fff;
    color: #b42318;
    border: 1px solid #fda29b;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 13px;
    cursor: pointer;
}

.btn-cancel-hosting:hover {
    background: #fef3f2;
}

.hosting-status-active {
    background: #ecfdf5;
    color: #047857;
}

.hosting-status-cancelled {
    background: #f2f4f7;
    color: #667085;
}

/* ─── Backup button ─────────────────────── */

.sidebar-backup-btn {
    background: rgba(255, 255, 255, 0.08);
    color: #d0d5dd;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    cursor: pointer;
    width: 100%;
    text-align: right;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.sidebar-backup-btn:hover {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.22);
    color: #fff;
}

.sidebar-backup-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ─── Backup toast notification ─────────── */

.backup-toast {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 9999;
    background: #027a48;
    color: #fff;
    padding: 14px 24px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(2, 122, 72, 0.3);
    transition: opacity 0.3s, transform 0.3s;
    transform: translateY(0);
    opacity: 1;
}

.backup-toast.hidden {
    opacity: 0;
    transform: translateY(16px);
    pointer-events: none;
}

.backup-toast-error {
    background: #b42318;
    box-shadow: 0 8px 24px rgba(180, 35, 24, 0.3);
}

/* ─── Backup management page ───────────── */

.btn-create-backup {
    background: #027a48;
}

.btn-create-backup:hover {
    background: #05603a;
}

.btn-delete-backup {
    background: #b42318;
    font-size: 13px;
    padding: 6px 12px;
}

.btn-delete-backup:hover {
    background: #911d14;
}

.btn-download-backup {
    background: #1d4ed8;
    font-size: 13px;
    padding: 6px 12px;
    text-decoration: none;
    color: #fff;
    display: inline-block;
    vertical-align: middle;
}

.btn-download-backup:hover {
    background: #1e40af;
    color: #fff;
    text-decoration: none;
}

.backup-filename {
    font-family: monospace;
    font-size: 13px;
    direction: ltr;
    unicode-bidi: embed;
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: #f3f4f6;
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 28px;
}

.login-card h1 {
    margin: 0 0 8px;
    font-size: 1.5rem;
}

.login-subtitle {
    margin: 0 0 20px;
    color: #6b7280;
    font-size: 0.95rem;
}

.sidebar-logout {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
}

.sidebar-logout .sidebar-backup-btn {
    width: 100%;
    background: #374151;
}

.sidebar-logout .sidebar-backup-btn:hover {
    background: #1f2937;
}
