:root {
    --bg: #f6f6f6;
    --sidebar-bg: #333333;
    --sidebar-text: #f5f5f5;
    --accent: #992626;
    --accent-hover: #b03939;
    --border: #e0e0e0;
    --text: #333333;
    --muted: #777777;
    --card-bg: #ffffff;
    --danger: #cc3333;
}

/* ===== Base ===== */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* ===== Layout ===== */
.layout {
    display: flex;
    flex-direction: column; /* меню сверху, контент ниже */
    min-height: 100vh;
}

/* ===== Sidebar (топ-бар) ===== */
.sidebar {
    width: 100%;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 10px 16px;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 20;
}

.sidebar-logo {
    font-size: 18px;
    margin: 0;
    margin-right: 24px;
    white-space: nowrap;
}

.sidebar-logo a {
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* Навигация */
.sidebar-nav {
    display: flex;
    flex-direction: row;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
    flex: 1;
}

.sidebar-nav-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #bfbfbf;
    margin-bottom: 4px;
}

.sidebar-link {
    color: var(--sidebar-text);
    text-decoration: none;
    padding: 4px 0;
    font-size: 14px;
    display: inline-block;
}

.sidebar-link:hover {
    color: #ffffff;
}

/* корневой и вложенный пункты меню */
.sidebar-link-root {
    font-weight: 600;
}

.sidebar-link-sub {
    padding-left: 0; /* сбрасываем, так как меню в одну линию */
    font-size: 0.95rem;
}

/* Блоки справа (синхронизация + выход) */
.sidebar-footer {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    margin-left: 16px;
}

.sidebar-logout {
    display: inline-block;
    padding: 6px 10px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14px;
    border-radius: 6px;
    background: transparent;
}

.sidebar-logout:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
}

/* Кнопка синхронизации с Google */
.sidebar-sync-btn {
    width: 100%;
    display: inline-block;
    padding: 8px 12px;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    background: #22c55e;
    color: #0f172a;
    font-weight: 600;
    text-align: center;
    transition: background 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
}

.sidebar-sync-btn:hover {
    background: #16a34a;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.sidebar-sync-btn:disabled {
    opacity: 0.6;
    cursor: default;
    transform: none;
    box-shadow: none;
}

/* Анимации статуса и кнопки при выполнении */
@keyframes syncStatusBlink {
    0%   { opacity: 0.6; }
    50%  { opacity: 1; }
    100% { opacity: 0.6; }
}

@keyframes syncButtonPulse {
    0%   { transform: scale(1); box-shadow: 0 0 0 rgba(34, 197, 94, 0); }
    50%  { transform: scale(1.03); box-shadow: 0 0 10px rgba(34, 197, 94, 0.6); }
    100% { transform: scale(1); box-shadow: 0 0 0 rgba(34, 197, 94, 0); }
}

.sync-status-running {
    animation: syncStatusBlink 1.2s infinite ease-in-out;
}

.sidebar-sync-btn-running {
    animation: syncButtonPulse 1.4s infinite ease-in-out;
}

/* ===== Main ===== */
.main {
    flex: 1;
    padding: 24px 32px;
}

/* ===== Page header ===== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.page-title {
    font-size: 24px;
    margin: 0;
}

.page-subtitle {
    margin: 4px 0 0 0;
    font-size: 13px;
    color: var(--muted);
}

/* ===== Cards ===== */
.card {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    margin-bottom: 24px;
}

.card h2,
.card h3 {
    margin-top: 0;
}

.section-title {
    font-size: 18px;
    margin: 0 0 12px 0;
}

/* Карточка с прикреплением контактов фиксированной высоты */
.card-fixed-contacts {
    height: 500px;
    display: flex;
    flex-direction: column;
}

/* Таблица внутри растягивается и скроллится */
.card-fixed-contacts .table-wrapper {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

/* ===== Buttons (общие) ===== */
.btn {
    display: inline-block;
    padding: 8px 14px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    text-decoration: none;
    font-family: inherit;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: #e9e9e9;
    color: var(--text);
}

.btn-secondary:hover {
    background: #d5d5d5;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #a52828;
}

/* ===== Forms ===== */
form .form-row {
    margin-bottom: 5px;
}

form label {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 4px;
}

/* Унифицированный вид всех input/textarea */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
textarea,
select {
    width: 100%;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 14px;
    background: #fff;
    font-family: inherit;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(153, 38, 38, 0.18);
}

textarea {
    resize: vertical;
}

.form-actions {
    margin-top: 12px;
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Обёртка для даты */
.date-input-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 100%;
}

.date-input-wrapper input[type="date"] {
    width: 100%;
    padding-right: 28px;
}

/* ===== Tables ===== */
.table-wrapper {
    max-width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    table-layout: fixed;
}

thead {
    background: #f2f2f2;
}

th,
td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

th {
    font-weight: 600;
    color: var(--muted);
}

tr:last-child td {
    border-bottom: none;
}

/* ===== Links ===== */
a.link {
    color: #993333;
    text-decoration: none;
}

a.link:hover {
    color: #993333;
    text-decoration: none;
}

/* ===== Misc ===== */
.muted {
    color: var(--muted);
    font-size: 13px;
}

.mt-16 {
    margin-top: 16px;
}

.mt-24 {
    margin-top: 24px;
}

/* ===== Journal (журнал заметок) ===== */
.journal-new {
    padding: 0;
}

.journal-header {
    padding: 10px 16px;
    background: #fcecec;
    border-radius: 10px 10px 0 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.journal-header-title {
    font-weight: 500;
    color: #4b5563;
}

.journal-new-form {
    padding: 16px;
}

.journal-save-btn {
    width: 100%;
}

.journal-list {
    margin-top: 0px;
    padding: 0;
}

.journal-search-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.journal-search-form input[type="text"],
.journal-search-form input[type="date"] {
    flex: 1;
    max-width: 220px;
}

.journal-items {
    padding: 12px 16px 16px 16px;
}

.journal-item {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 10px;
    background: #fff;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.journal-item-editing {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(153, 38, 38, 0.25);
}

.journal-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.journal-item-meta {
    display: flex;
    gap: 10px;
    font-size: 13px;
    color: var(--muted);
    align-items: center;
}

.journal-item-actions {
    display: flex;
    gap: 4px;
}

.journal-item-date {
    font-size: 12px;
    color: #7e7e7e;
}

.journal-icon-btn {
    border: none;
    background: #e9e9e9;
    border-radius: 6px;
    padding: 4px 6px;
    cursor: pointer;
    font-size: 14px;
}

.journal-icon-btn:hover {
    background: #d5d5d5;
}

.journal-icon-btn-danger {
    background: #fde2e2;
    color: #a52828;
}

.journal-icon-btn-danger:hover {
    background: #fdcaca;
}

.journal-item-body {
    margin-top: 4px;
}

.journal-item-textarea {
    width: 100%;
    border-radius: 6px;
    border: 1px solid var(--border);
    padding: 6px 8px;
    font-size: 14px;
    resize: vertical;
}

/* Inputs в режиме редактирования */
.journal-edit-input[disabled] {
    background: #f9fafb;
}

/* ===== Helpers / Responsive ===== */
@media (max-width: 1024px) {
    .client-detail-grid {
        display: block !important;
    }

    .main {
        padding: 16px 12px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .page-title {
        font-size: 20px;
    }

    .card {
        padding: 16px;
        margin-bottom: 16px;
    }

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

    .form-actions .btn {
        width: 100%;
        text-align: center;
    }

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

    .journal-search-form input[type="text"],
    .journal-search-form input[type="date"] {
        max-width: 100%;
    }
}

/* Маленькие экраны */
@media (max-width: 600px) {
    .sidebar {
        flex-direction: column;
        align-items: flex-start;
        padding: 12px 10px;
    }

    .sidebar-logo {
        text-align: left;
        margin-bottom: 8px;
        margin-right: 0;
    }

    .sidebar-nav {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 4px 10px;
        width: 100%;
    }

    .sidebar-link {
        font-size: 13px;
        padding: 2px 0;
    }

    .sidebar-footer {
        align-items: flex-start;
        margin-left: 0;
        margin-top: 8px;
    }

    .main {
        padding: 12px 10px;
    }

    table {
        font-size: 13px;
    }

    th,
    td {
        padding: 6px 6px;
    }
}


.sidebar-link-active {
    background-color: #993333;
    padding: 5px;
    border-radius: 3px;
    color: #ffffff;
}

.sidebar-link-active.sidebar-link-sub {
    font-weight: 600;
}

