:root {
    --bg: #f0f0f0;
    --sidebar-bg: #ffffff;
    --editor-bg: #ffffff;
    --accent: #007bff;
    --danger: #dc3545;
    --text: #333333;
    --muted: #666666;
    --border: #dddddd;
    --crossed: #999999;
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.app {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

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

.sidebar-header h1 {
    margin: 0;
    font-size: 18px;
}

.notes-list {
    flex: 1;
    overflow-y: auto;
}

.note-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f5f5f5;
    transition: background .15s;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    position: relative;
}

.note-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 4px;
    border-radius: 0 2px 2px 0;
    background: transparent;
}

.note-item.has-color::before {
    background: var(--note-color, var(--border));
}

.note-item:hover,
.note-item.active {
    background: #f5f5f5;
}

.note-item .note-title {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.note-item .note-date {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
}

.note-item .note-author {
    font-size: 11px;
    font-weight: 600;
}

.note-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.note-delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: var(--danger);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
    flex-shrink: 0;
    opacity: 0.6;
    transition: opacity .15s, background .15s;
}

.note-delete:hover {
    opacity: 1;
    background: rgba(220, 53, 69, 0.1);
}

.note-delete.hidden {
    display: none;
}

.empty-state {
    padding: 20px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}

/* Editor */
.editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    min-width: 0;
}

.editor-header {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 8px;
}

.plate-input-wrap {
    position: relative;
    flex: 0 0 auto;
    width: 220px;
}

#note-title {
    width: 100%;
    padding: 10px 12px;
    font-size: 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    outline: none;
}

#note-title:focus {
    border-color: var(--accent);
}

.plate-suggestions {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 240px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
}

.plate-suggestions.active {
    display: block;
}

.plate-suggestion-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid #f5f5f5;
}

.plate-suggestion-item:last-child {
    border-bottom: none;
}

.plate-suggestion-item:hover,
.plate-suggestion-item.active {
    background: #f0f7ff;
}

.plate-suggestion-plate {
    font-weight: 600;
}

.plate-suggestion-vin {
    font-size: 12px;
    color: var(--muted);
    font-family: "Courier New", Courier, monospace;
}

#notes-search {
    flex: 1;
    padding: 10px 14px;
    font-size: 15px;
    border: 1px solid var(--border);
    border-radius: 20px;
    outline: none;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23999' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z'/%3E%3C/svg%3E") no-repeat 12px center;
    padding-left: 34px;
}

#notes-search:focus {
    border-color: var(--accent);
}

#notes-search::-webkit-search-cancel-button {
    cursor: pointer;
}

.save-status {
    font-size: 12px;
    color: var(--muted);
    min-width: 90px;
    text-align: right;
}

.editor-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

#btn-voice,
#btn-photo {
    padding: 8px 12px;
    font-size: 16px;
    line-height: 1;
}

#btn-voice.recording {
    animation: pulse-red 1.2s infinite;
    background: var(--danger);
}

@keyframes pulse-red {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

.editor-meta {
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--muted);
    min-height: 18px;
}

.editor-meta .author-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.editor {
    flex: 1;
    background: var(--editor-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    font-family: "Courier New", Courier, monospace;
    font-size: 16px;
    line-height: 1.6;
    overflow-y: auto;
    outline: none;
    word-break: break-word;
}

.editor:focus {
    border-color: var(--accent);
}

.editor span[data-user-color] {
    padding: 1px 2px;
    border-radius: 2px;
}

.editor .crossed-out {
    text-decoration: line-through;
    color: var(--crossed);
    background: transparent !important;
}

.editor .active-line {
    background: #f0f7ff;
    border-radius: 4px;
    outline: 1px solid var(--accent);
    outline-offset: -1px;
}

.editor-footer {
    margin-top: 8px;
    color: var(--muted);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .15s;
}

.btn:hover {
    opacity: .85;
}

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

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

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
}

.btn-sm:hover {
    background: var(--bg);
    opacity: 1;
}

.work-footer {
    margin-top: 12px;
    padding: 12px 16px;
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: "Courier New", Courier, monospace;
    font-size: 14px;
    line-height: 1.5;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.work-footer-section {
    flex: 1 1 auto;
    min-width: 140px;
}

.work-total {
    font-weight: bold;
    color: var(--text);
    margin-bottom: 4px;
}

.work-person {
    color: var(--muted);
    padding-left: 12px;
}

.balance-negative {
    font-weight: bold;
}

.balance-zero {
    font-weight: bold;
}

.balance-positive {
    font-weight: bold;
}

.vin-valid {
    background-color: #d4edda !important;
    color: #155724 !important;
    padding: 1px 2px;
    border-radius: 2px;
}

.vin-invalid {
    background-color: #f8d7da !important;
    color: #721c24 !important;
    padding: 1px 2px;
    border-radius: 2px;
}

/* Photo area */
.photo-area {
    margin-top: 12px;
    padding: 12px 16px;
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-radius: 8px;
    display: none;
}

.photo-area.visible {
    display: block;
}

.photo-area-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.photo-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.photo-thumb {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
    cursor: pointer;
    background: #fff;
    flex-shrink: 0;
}

.photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.photo-delete {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    background: rgba(220, 53, 69, 0.9);
    color: #fff;
    border: none;
    border-radius: 3px;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    z-index: 2;
}

.photo-delete:hover {
    background: rgba(220, 53, 69, 1);
}

/* Photo modal */
.photo-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    padding-top: 60px;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.9);
}

.photo-modal.active {
    display: block;
}

.photo-modal-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 80vh;
    border-radius: 4px;
}

.photo-modal-close {
    position: absolute;
    top: 20px;
    right: 30px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.photo-modal-close:hover {
    color: #bbb;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 200px;
    }
    .plate-input-wrap,
    #notes-search {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .plate-input-wrap,
    #notes-search {
        width: 100%;
    }
}

/* Catalog modal */
.catalog-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    padding-top: 40px;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
}

.catalog-modal.active {
    display: block;
}

.catalog-modal-content {
    background: #fff;
    margin: 0 auto;
    width: 90%;
    max-width: 98vw;
    max-height: 90vh;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    resize: both;
    position: relative;
    min-width: 320px;
    min-height: 200px;
}

.catalog-modal-content::after {
    content: '';
    position: absolute;
    right: 4px;
    bottom: 4px;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 50%, var(--border) 50%);
    pointer-events: none;
    z-index: 10;
}

.catalog-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: #f8f9fa;
}

.catalog-modal-header h3 {
    margin: 0;
    font-size: 16px;
}

.catalog-modal-close {
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    color: var(--muted);
}

.catalog-search-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    justify-content: flex-end;
    margin-right: 12px;
}

.catalog-search-wrap input {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    width: 220px;
    outline: none;
}

.catalog-search-wrap input:focus {
    border-color: var(--accent);
}

.catalog-search-wrap button {
    padding: 5px 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
}

.catalog-search-wrap button:hover {
    background: #0056b3;
}

.catalog-modal-close:hover {
    color: var(--text);
}

.catalog-modal-body {
    flex: 1;
    overflow: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
}

.catalog-vehicle-title {
    font-weight: bold;
    margin-bottom: 8px;
    color: var(--text);
}

/* Tree layout */
.catalog-layout {
    display: flex;
    gap: 16px;
    flex: 1;
    min-height: 0;
    margin-top: 8px;
}

.catalog-tree {
    width: 320px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding-right: 8px;
    font-size: 13px;
}

.catalog-detail-panel {
    flex: 1;
    overflow-y: auto;
    min-width: 0;
}

.catalog-loading {
    text-align: center;
    padding: 20px;
    color: var(--muted);
}

/* Tree nodes */
.catalog-tree-node {
    user-select: none;
}

.catalog-tree-row {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background .15s;
    gap: 4px;
}

.catalog-tree-row:hover {
    background: #f0f0f0;
}

.catalog-tree-row.active {
    background: #e7f1ff;
}

.catalog-tree-toggle {
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--muted);
    flex-shrink: 0;
    cursor: pointer;
}

.catalog-tree-toggle:hover {
    color: var(--text);
}

.catalog-tree-children {
    display: none;
    padding-left: 16px;
}

.catalog-tree-children.expanded {
    display: block;
}

.catalog-tree-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.catalog-tree-name.searchable {
    color: var(--accent);
}

/* Detail panel */
.catalog-category-title {
    font-weight: bold;
    margin-top: 12px;
    margin-bottom: 4px;
    font-size: 14px;
    color: var(--text);
}

.catalog-unit {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background .15s;
}

.catalog-unit:hover {
    background: #f0f0f0;
}

.catalog-unit-thumb {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.catalog-unit-detail-wrap {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.catalog-unit-imgwrap {
    flex: 1 1 300px;
    position: relative;
}

.catalog-unit-imgwrap img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

.catalog-map-wrap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.catalog-zone {
    position: absolute;
    border: 2px solid rgba(255, 0, 0, 0.5);
    background: rgba(255, 0, 0, 0.15);
    cursor: pointer;
    transition: background .15s;
}

.catalog-zone:hover,
.catalog-zone-hover {
    background: rgba(255, 0, 0, 0.4);
}

.catalog-unit-tblwrap {
    flex: 1 1 300px;
    min-width: 0;
}

.catalog-parts-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.catalog-parts-table th,
.catalog-parts-table td {
    padding: 6px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.catalog-parts-table th {
    font-weight: 600;
    background: #f8f9fa;
}

.catalog-row-highlight {
    background: #fff3cd !important;
}

/* ROSSKO pricing panel */
.rossko-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.rossko-header h4 {
    margin: 0;
    font-size: 15px;
    color: var(--text);
}

.btn-back-rossko {
    background: #f0f0f0;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    color: var(--text);
}

.btn-back-rossko:hover {
    background: #e0e0e0;
}

.rossko-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.rossko-table th,
.rossko-table td {
    padding: 8px 6px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.rossko-table th {
    font-weight: 600;
    background: #f8f9fa;
    font-size: 11px;
    white-space: nowrap;
}

.rossko-table td {
    color: var(--text);
}

.rossko-table tr:hover {
    background: #f8f9fa;
}

.rossko-cross {
    color: #dc3545;
    font-size: 10px;
}

.rossko-delivery-green {
    background-color: #d4edda;
}

.rossko-delivery-blue {
    background-color: #d1ecf1;
}

.rossko-delivery-yellow {
    background-color: #fff3cd;
}

.rossko-qty {
    width: 48px;
    padding: 2px 4px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
    text-align: center;
}

.btn-rossko-cart {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 5px 10px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}

.btn-rossko-cart:hover {
    background: #0056b3;
}

.btn-rossko-cart.added {
    background: #28a745;
    cursor: default;
}

/* Вкладки поставщиков в каталоге */
.supplier-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 10px;
}

.supplier-tab {
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    padding: 8px 16px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text);
}

.supplier-tab:hover {
    background: #e9ecef;
}

.supplier-tab.active {
    background: #fff;
    border-bottom: 1px solid #fff;
    margin-bottom: -1px;
    font-weight: 600;
}

.supplier-panels {
    position: relative;
}

.supplier-tab-panel {
    display: none;
}

.supplier-tab-panel.active {
    display: block;
}

.supplier-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    padding: 2px 8px;
    border-radius: 12px;
    vertical-align: middle;
}

.supplier-qty {
    width: 48px;
    padding: 2px 4px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
    text-align: center;
}

@media (max-width: 480px) {
    .app {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        height: 40%;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .editor-actions {
        flex-wrap: wrap;
    }
    #btn-voice {
        flex: 1 1 100%;
        width: 100%;
        padding: 12px;
        font-size: 18px;
    }
}
