/* ===== Design tokens ===== */
:root {
    --color-bg: #f5f6f8;
    --color-surface: #ffffff;
    --color-text: #191c22;
    --color-text-muted: #6b7280;
    --color-border: #e6e8ec;
    --color-primary: #4f46e5;
    --color-primary-hover: #4338ca;
    --color-success: #16a34a;
    --color-danger: #dc2626;
    --color-warning: #a16207;
    --color-link: #4f46e5;
    color-scheme: light;

    --color-border-strong: #c7cbd3;
    --color-hover: #fafbfc;
    --color-skeleton: #e5e7eb;
    --color-primary-soft: #eef0ff;
    --color-danger-bg: #fdecea;
    --color-danger-border: #f3c9c9;
    --color-danger-text: #a52a1f;
    --color-disabled-bg: #e3e5e8;
    --color-disabled-field-bg: #f0f1f3;
    --color-disabled-text: #9aa0a8;
    --color-warn-bg: #fff7ed;
    --color-warn-border: #fed7aa;
    --color-warn-text: #9a3412;
    --color-badge-owner-bg: #fef3c7;
    --color-badge-admin-bg: #e0e7ff;
    --color-badge-user-bg: #f1f2f4;
    --color-cover-bg: rgba(255, 255, 255, 0.85);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;

    --topbar-height: 56px;
    --content-max: 1600px;
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1 {
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 var(--space-4);
}

h2 {
    font-size: 15px;
    font-weight: 600;
}

a {
    color: var(--color-link);
}

/* ===== Buttons ===== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
    white-space: nowrap;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    width: 100%;
}

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

.btn-secondary {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-text);
}

.btn-secondary:hover {
    border-color: var(--color-border-strong);
}

.btn-danger {
    background: var(--color-surface);
    border: 1px solid var(--color-danger-border);
    color: var(--color-danger);
}

.btn-danger:hover {
    background: var(--color-danger-bg);
}

.link-btn {
    background: none;
    border: none;
    color: var(--color-link);
    cursor: pointer;
    font-size: 13px;
    padding: 0;
}

/* ===== Forms ===== */

.field {
    display: block;
    margin-bottom: var(--space-4);
    font-size: 12.5px;
    color: var(--color-text-muted);
    font-weight: 500;
}

.field input,
.field select,
.field textarea {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    color: var(--color-text);
    background: var(--color-surface);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.alert {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: var(--space-4);
}

.alert-error {
    background: var(--color-danger-bg);
    color: var(--color-danger-text);
}

/* ===== Login page ===== */

.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}

.login-form {
    background: var(--color-surface);
    padding: var(--space-6) var(--space-5);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 340px;
}

/* ===== Topbar ===== */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 var(--space-5);
    height: var(--topbar-height);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 300;
    gap: var(--space-4);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: var(--space-5);
    min-width: 0;
}

.topbar-title {
    color: var(--color-text);
    text-decoration: none;
    font-size: 14px;
    white-space: nowrap;
}

.topbar-links {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    overflow-x: auto;
}

.topbar-link {
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 13.5px;
    white-space: nowrap;
}

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

.topbar-user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: 13.5px;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.notif-bell-wrap {
    position: relative;
}

.notif-bell-btn {
    position: relative;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-muted);
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
}

.notif-bell-btn:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.notif-bell-badge {
    position: absolute;
    top: 0;
    right: 0;
    background: #e5484d;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
}

.notif-dropdown {
    position: fixed;
    width: 320px;
    max-width: calc(100vw - 24px);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 2100;
    overflow: hidden;
}

.notif-dropdown-list {
    max-height: 360px;
    overflow-y: auto;
}

.notif-item:hover {
    background: var(--color-bg) !important;
}

.notif-dropdown-all {
    display: block;
    text-align: center;
    padding: 10px;
    font-size: 12.5px;
    color: var(--color-link);
    text-decoration: none;
    border-top: 1px solid var(--color-border);
}

.notif-dropdown-all:hover {
    background: var(--color-bg);
}

.topbar-profile {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--color-text);
}

.topbar-profile span {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inline-form {
    display: inline;
}

/* ===== Layout ===== */

.content {
    padding: var(--space-5);
    max-width: var(--content-max);
    margin: 0 auto;
}

.sections {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--space-4);
}

.section-card {
    display: block;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    padding: var(--space-5);
    border-radius: var(--radius-md);
    text-align: center;
    text-decoration: none;
    color: var(--color-text);
    font-weight: 500;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.section-card:hover {
    box-shadow: var(--shadow-sm);
    border-color: var(--color-border-strong);
}

/* ===== Avatars ===== */

.avatar-sm {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    flex-shrink: 0;
}

.avatar-lg {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--color-skeleton);
    display: block;
    margin-bottom: var(--space-4);
}

.avatar-clickable {
    cursor: zoom-in;
}

/* ===== Cards ===== */

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    margin-bottom: var(--space-4);
    max-width: 100%;
    width: 100%;
}

.card h2 {
    margin: 0 0 var(--space-4);
}

.info-row {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 9px 0;
    border-bottom: 1px solid var(--color-border);
    font-size: 13.5px;
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    color: var(--color-text-muted);
}

.checkins-table {
    table-layout: fixed;
    width: 100%;
}

.checkins-table td,
.checkins-table th {
    white-space: normal !important;
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
    vertical-align: top;
}

/* ===== Square icon buttons — download/delete/edit for file rows, checkins, and similar
   small per-row actions everywhere on the site. Same size, no text, just an icon. ===== */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0;
    text-decoration: none;
}

.icon-btn:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.icon-btn-delete:hover {
    color: var(--color-danger);
    border-color: var(--color-danger);
}

.icon-btn::before {
    content: "";
    display: block;
    width: 15px;
    height: 15px;
    background-color: currentColor;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: contain;
    mask-size: contain;
}

.icon-btn-download::before {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4'/%3E%3Cpolyline points='7 10 12 15 17 10'/%3E%3Cline x1='12' y1='15' x2='12' y2='3'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4'/%3E%3Cpolyline points='7 10 12 15 17 10'/%3E%3Cline x1='12' y1='15' x2='12' y2='3'/%3E%3C/svg%3E");
}

.icon-btn-delete::before {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18'/%3E%3Cpath d='M8 6V4a2 2 0 012-2h4a2 2 0 012 2v2'/%3E%3Cpath d='M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6'/%3E%3Cline x1='10' y1='11' x2='10' y2='17'/%3E%3Cline x1='14' y1='11' x2='14' y2='17'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18'/%3E%3Cpath d='M8 6V4a2 2 0 012-2h4a2 2 0 012 2v2'/%3E%3Cpath d='M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6'/%3E%3Cline x1='10' y1='11' x2='10' y2='17'/%3E%3Cline x1='14' y1='11' x2='14' y2='17'/%3E%3C/svg%3E");
}

.icon-btn-edit::before {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7'/%3E%3Cpath d='M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7'/%3E%3Cpath d='M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z'/%3E%3C/svg%3E");
}

.icon-btn-group {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

@media (max-width: 480px) {
    .checkins-table col:nth-child(1) { width: 78px !important; }
    .checkins-table col:nth-child(2) { width: 70px !important; }
    .checkins-table col:nth-child(4) { width: 0 !important; }
    .checkins-table th:nth-child(4),
    .checkins-table td:nth-child(4) {
        display: none;
    }
    .checkins-table th,
    .checkins-table td {
        padding: 8px 6px;
        font-size: 12px;
    }
}

/* ===== Tables ===== */

.table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

table.data-table th,
table.data-table td {
    padding: 10px 14px;
    text-align: left;
    font-size: 13.5px;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

table.data-table th {
    color: var(--color-text-muted);
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

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

table.data-table tr:hover {
    background: var(--color-hover);
}

/* ===== Badges ===== */

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
}

.badge-owner {
    background: var(--color-badge-owner-bg);
    color: var(--color-warning);
}

.badge-admin {
    background: var(--color-badge-admin-bg);
    color: var(--color-link);
}

.badge-user {
    background: var(--color-badge-user-bg);
    color: var(--color-text-muted);
}

.badge-inactive {
    background: var(--color-danger-bg);
    color: var(--color-danger-text);
}

/* ===== Toasts ===== */

#toast-container {
    position: fixed;
    top: var(--space-4);
    right: var(--space-4);
    left: var(--space-4);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    z-index: 1000;
    pointer-events: none;
}

.toast-close-all {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    color: var(--color-text);
    box-shadow: var(--shadow-sm);
    pointer-events: auto;
}

.toast {
    position: relative;
    min-width: 240px;
    max-width: 360px;
    padding: 12px 34px 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: #fff;
    opacity: 0;
    transform: translateX(20px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    box-shadow: var(--shadow-md);
    pointer-events: auto;
}

.toast-visible {
    opacity: 1;
    transform: translateX(0);
}

.toast-success {
    background: var(--color-success);
}

.toast-error {
    background: var(--color-danger);
}

.toast-time {
    margin-top: 4px;
    font-size: 11px;
    opacity: 0.8;
}

.toast-close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: none;
    border: none;
    color: #fff;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.8;
    padding: 2px 4px;
}

.toast-close:hover {
    opacity: 1;
}

/* ===== Avatar uploader ===== */

.avatar-progress {
    max-width: 200px;
    height: 6px;
    background: var(--color-skeleton);
    border-radius: 3px;
    overflow: hidden;
    margin: var(--space-3) 0;
}

.avatar-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--color-primary);
    transition: width 0.15s ease;
}

/* ===== Photo grid (gallery) ===== */

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: var(--space-2);
    margin: var(--space-3) 0;
}

.photo-cell {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--color-skeleton);
    border: 1px solid var(--color-border);
}

.photo-cell img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: zoom-in;
    display: block;
}

.photo-cell-uploading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2);
}

.photo-cell-uploading .avatar-progress-bar {
    height: 4px;
}

.photo-cell-delete,
.photo-cell-cover {
    position: absolute;
    top: 4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.photo-cell-delete {
    right: 4px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
}

.photo-cell-cover {
    left: 4px;
    background: var(--color-cover-bg);
    color: var(--color-warning);
}

.photo-cell-cover.is-cover {
    color: #fff;
    background: var(--color-warning);
}

.tool-cover-thumb {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    background: var(--color-skeleton);
    display: block;
}

.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-4);
}

.tool-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    text-decoration: none;
    color: var(--color-text);
    display: block;
    transition: box-shadow 0.15s ease;
}

.tool-card:hover {
    box-shadow: var(--shadow-sm);
}

.tool-card-body {
    padding: var(--space-3) var(--space-4);
}

.tool-card-name {
    font-weight: 500;
    font-size: 13.5px;
}

/* ===== Photo viewer (lightbox/slider) ===== */

.photo-viewer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.photo-viewer-image {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    transition: opacity 0.15s ease;
}

.photo-viewer-image.photo-viewer-loading {
    opacity: 0.5;
}

.photo-viewer-close {
    position: absolute;
    top: 16px;
    right: 20px;
    background: none;
    border: none;
    color: #fff;
    font-size: 30px;
    cursor: pointer;
    line-height: 1;
}

.photo-viewer-prev,
.photo-viewer-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    font-size: 26px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.photo-viewer-prev {
    left: 12px;
}

.photo-viewer-next {
    right: 12px;
}

.photo-viewer-counter {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 12.5px;
    background: rgba(0, 0, 0, 0.4);
    padding: 4px 12px;
    border-radius: 12px;
}

/* ===== Page-lock banner ===== */

.lock-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    background: var(--color-warn-bg);
    border: 1px solid var(--color-warn-border);
    color: var(--color-warn-text);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: var(--space-4);
    max-width: 560px;
}

/* Заблокированные поля/кнопки — явно серые, а не просто слегка прозрачные */
.field input:disabled,
.field select:disabled,
.field textarea:disabled {
    background: var(--color-disabled-field-bg);
    color: var(--color-disabled-text);
    border-color: var(--color-border);
    cursor: not-allowed;
}

.btn:disabled {
    background: var(--color-disabled-bg) !important;
    color: var(--color-disabled-text) !important;
    border-color: var(--color-disabled-bg) !important;
    cursor: not-allowed;
    box-shadow: none;
}

.photo-cell-delete:disabled,
.photo-cell-cover:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ===== Comments ===== */

.comment {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--color-border);
    align-items: flex-start;
}

.comment:last-child {
    border-bottom: none;
}

.comment-body {
    flex: 1;
    min-width: 0;
}

.comment-author {
    font-weight: 500;
    font-size: 13px;
}

.comment-time {
    color: var(--color-text-muted);
    font-size: 11.5px;
    margin-left: 8px;
}

.comment-text {
    font-size: 13.5px;
    margin-top: 2px;
    white-space: pre-wrap;
    word-break: break-word;
}

.comment-delete {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 4px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    line-height: 0;
}

.comment-delete:hover {
    color: var(--color-danger);
    background: var(--color-bg);
}

.comment-delete::before {
    content: "";
    display: block;
    width: 15px;
    height: 15px;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18'/%3E%3Cpath d='M8 6V4a2 2 0 012-2h4a2 2 0 012 2v2'/%3E%3Cpath d='M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6'/%3E%3Cline x1='10' y1='11' x2='10' y2='17'/%3E%3Cline x1='14' y1='11' x2='14' y2='17'/%3E%3C/svg%3E") no-repeat center / contain;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18'/%3E%3Cpath d='M8 6V4a2 2 0 012-2h4a2 2 0 012 2v2'/%3E%3Cpath d='M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6'/%3E%3Cline x1='10' y1='11' x2='10' y2='17'/%3E%3Cline x1='14' y1='11' x2='14' y2='17'/%3E%3C/svg%3E") no-repeat center / contain;
    background-color: currentColor;
}

/* Единый вид блока комментариев на всех страницах: поле ввода сверху (form),
   зафиксированное по ширине, чуть выше обычного textarea; сами комментарии — ниже. */
.comment-form {
    margin-bottom: var(--space-4);
}

.comment-form textarea {
    width: 100%;
    min-height: 80px;
    resize: vertical;
    box-sizing: border-box;
}

/* ===== Permissions grid ===== */

.perm-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--color-border);
    font-size: 13.5px;
}

.perm-row:last-child {
    border-bottom: none;
}

.perm-checks {
    display: flex;
    gap: var(--space-4);
}

.perm-checks label {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--color-text-muted);
    font-size: 12.5px;
    cursor: pointer;
}

/* ===== Mobile ===== */

@media (max-width: 640px) {
    .content {
        padding: var(--space-4) var(--space-3);
    }

    .topbar {
        padding: 0 var(--space-3);
        gap: var(--space-2);
    }

    .topbar-left {
        gap: var(--space-3);
    }

    .topbar-profile span {
        display: none;
    }

    .card {
        padding: var(--space-4);
        max-width: 100%;
    }

    table.data-table th,
    table.data-table td {
        padding: 8px 10px;
    }

    .sections,
    .tools-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    }

    #toast-container {
        left: var(--space-2);
        right: var(--space-2);
        top: var(--space-2);
        align-items: stretch;
    }

    .toast {
        max-width: 100%;
    }

    .lock-banner {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* ===== Tools list-view mode ===== */

.tools-grid-as-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.tools-grid-as-list .tool-card {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
}

.tools-grid-as-list .tool-cover-thumb {
    width: 56px;
    height: 56px;
    aspect-ratio: 1 / 1;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.tools-grid-as-list .tool-card-body {
    padding: 0;
}

/* ===== Side navigation (desktop) / bottom nav (mobile) ===== */

body.app {
    padding-left: 96px;
    padding-top: var(--topbar-height);
}

.side-nav {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    width: 96px;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 16px;
    gap: 4px;
    z-index: 200;
    overflow-y: auto;
}

.side-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 84px;
    padding: 10px 4px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--color-text-muted);
    font-size: 11px;
    text-align: center;
    flex-shrink: 0;
}

.side-nav-item:hover {
    background: var(--color-bg);
}

.side-nav-item.active {
    color: var(--color-link);
    background: var(--color-primary-soft);
}

.side-nav-icon svg {
    width: 22px;
    height: 22px;
    display: block;
}

.side-nav-label {
    text-align: center;
    white-space: normal;
    word-break: break-word;
    line-height: 1.2;
}

/* ===== Breadcrumb topbar ===== */

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13.5px;
    min-width: 0;
    overflow: hidden;
}

.breadcrumb-link {
    color: var(--color-text-muted);
    text-decoration: none;
    white-space: nowrap;
}

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

.breadcrumb-current {
    color: var(--color-text);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.breadcrumb-sep {
    color: var(--color-border);
}

@media (max-width: 900px) {
    body.app {
        padding-left: 0;
        padding-bottom: 84px;
    }

    .side-nav {
        top: auto;
        left: 8px;
        right: 8px;
        bottom: 8px;
        width: auto;
        height: 68px;
        flex-direction: row;
        justify-content: space-around;
        padding-top: 0;
        padding-left: 10px;
        padding-right: 10px;
        border-right: none;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-md);
    }

    .side-nav-item {
        width: auto;
        flex: 1;
    }

    .side-nav-icon svg {
        width: 24px;
        height: 24px;
    }

    .side-nav-label {
        display: none;
    }
}

/* ===== Search with clear button ===== */

.search-with-clear {
    position: relative;
    display: inline-block;
}

.search-with-clear input {
    padding-right: 32px !important;
}

.search-clear-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    padding: 4px;
    display: none;
}

.search-clear-btn.visible {
    display: block;
}

/* ===== Modal (popup) ===== */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, 0.5);
    align-items: center;
    justify-content: center;
    z-index: 1500;
    padding: 16px;
}

.modal-overlay.modal-open {
    display: flex;
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    padding: 24px;
    max-width: 420px;
    width: 100%;
    box-shadow: var(--shadow-md);
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-close {
    float: right;
    background: none;
    border: none;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    color: var(--color-text-muted);
}

/* ===== Two-column page layout (main content + comments/history sidebar) ===== */

.content-wide {
    max-width: 1600px;
}

.page-two-col {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 24px;
    align-items: start;
}

.page-side-toggle {
    display: none;
    width: 100%;
    margin-bottom: 16px;
}

.page-two-col .card {
    max-width: none;
    width: 100%;
}

.page-side-close {
    display: none;
}

@media (max-width: 900px) {
    .page-two-col {
        grid-template-columns: 1fr;
    }

    .page-side {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 1600;
        background: rgba(16, 24, 40, 0.5);
        align-items: flex-start;
        justify-content: center;
        padding: 12px;
        overflow-y: auto;
    }

    .page-side.open {
        display: flex;
    }

    .page-side .card {
        width: 100%;
        max-width: 480px;
        max-height: calc(100vh - 24px);
        overflow-y: auto;
        margin: 0;
        position: relative;
    }

    .page-side-toggle {
        display: inline-flex;
    }

    .page-side-close {
        display: block;
        position: absolute;
        top: 12px;
        right: 12px;
        background: none;
        border: none;
        font-size: 20px;
        line-height: 1;
        cursor: pointer;
        color: var(--color-text-muted);
    }
}

/* ===== Related tools / small-photo card blocks ===== */

.related-group {
    margin-bottom: 16px;
}

.related-group-label {
    font-size: 12px;
    color: var(--color-text-muted);
    font-weight: 500;
    margin-bottom: 8px;
    display: block;
}

.related-items {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.related-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 6px 10px 6px 6px;
    text-decoration: none;
    color: var(--color-text);
    font-size: 13px;
}

.related-item:hover {
    border-color: var(--color-border-strong);
}

.related-item img {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    object-fit: cover;
    background: var(--color-skeleton);
}

/* Блокировка скролла фона, пока открыт попап/просмотр фото */
body.no-scroll {
    overflow: hidden;
}

/* ===== Кнопка в процессе запроса (см. toast.js → acquireRequestLock) ===== */
button.is-loading,
.btn.is-loading,
.link-btn.is-loading,
.icon-btn.is-loading {
    opacity: 0.55;
    cursor: progress;
    pointer-events: none;
}

/* ===== Мобильная адаптивность: общие защитные правила ===== */

img, video, canvas, svg {
    max-width: 100%;
}

.card,
.modal,
.info-row,
.comment-text,
.related-item {
    overflow-wrap: anywhere;
}

/* Значения в строках «название — значение»: не сжимаются в узкий столбик */
.info-row > .info-label {
    flex: 0 0 auto;
}

.info-row > span:not(.info-label) {
    min-width: 0;
}

.perm-row {
    flex-wrap: wrap;
    gap: var(--space-2);
}

.perm-checks {
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-4);
}

@media (max-width: 640px) {
    html, body {
        max-width: 100vw;
        overflow-x: hidden;
    }

    .content {
        padding-left: var(--space-3);
        padding-right: var(--space-3);
    }

    /* Строки «заголовок + кнопки» с инлайн-flex переносятся, а не вылезают за экран.
       Исключаем ряды с ellipsis (min-width:0) — там перенос ломает обрезку длинных имён. */
    main [style*="display:flex"]:not([style*="flex-direction"]):not([style*="min-width:0"]):not([style*="justify-content:center"]) {
        flex-wrap: wrap !important;
    }

    main [style*="display:flex"][style*="gap"] > .btn,
    main [style*="display:flex"][style*="gap"] > a.btn {
        flex: 1 1 auto;
    }

    /* Подпись и значение: перенос значения под подпись вместо схлопывания в столбик */
    .info-row {
        flex-wrap: wrap;
        gap: 2px var(--space-3);
    }

    .info-row > span:not(.info-label):not(.icon-btn-group):not(.badge) {
        flex: 1 1 140px;
        text-align: right;
    }

    /* Строки с кнопками-иконками (файлы и т.п.) — не переносим, имя обрезаем */
    .info-row:has(.icon-btn-group) {
        flex-wrap: nowrap;
        align-items: center;
    }

    .info-row:has(.icon-btn-group) > span {
        text-align: left;
        flex: 1 1 auto;
        min-width: 0;
    }

    /* Инпуты/селекты с инлайн-шириной не шире экрана */
    main input,
    main select,
    main textarea {
        max-width: 100%;
    }

    main form [style*="min-width"] {
        min-width: 0 !important;
        flex-basis: 100% !important;
    }

    h1 {
        font-size: 18px;
        overflow-wrap: anywhere;
    }

    .modal {
        padding: var(--space-4);
    }

    .related-items {
        gap: 6px;
    }

    .page-two-col {
        gap: var(--space-4);
    }

    .breadcrumb {
        font-size: 12.5px;
    }

    .topbar-user {
        gap: var(--space-2);
    }
}


/* =====================================================================
   Тёмная тема. Включается атрибутом <html data-theme="dark"> —
   его выставляет partials/head.php до отрисовки страницы (без вспышки).
   Выбор делается в профиле и хранится в user_preferences ('theme').
   ===================================================================== */

:root[data-theme="dark"] {
    color-scheme: dark;

    --color-bg: #0e1013;
    --color-surface: #171a20;
    --color-text: #e6e8ec;
    --color-text-muted: #9aa3b2;
    --color-border: #2a2f39;
    --color-primary: #6366f1;
    --color-primary-hover: #7578f4;
    --color-link: #9ea4ff;
    --color-success: #22a55a;
    --color-danger: #f0626a;
    --color-warning: #f0b24d;

    --color-border-strong: #3a414d;
    --color-hover: #1d2129;
    --color-skeleton: #262b34;
    --color-primary-soft: rgba(124, 131, 255, 0.16);
    --color-danger-bg: rgba(240, 98, 106, 0.14);
    --color-danger-border: rgba(240, 98, 106, 0.4);
    --color-danger-text: #f4a3a8;
    --color-disabled-bg: #242932;
    --color-disabled-field-bg: #1c2027;
    --color-disabled-text: #6b7482;
    --color-warn-bg: rgba(245, 158, 11, 0.12);
    --color-warn-border: rgba(245, 158, 11, 0.35);
    --color-warn-text: #f0b86a;
    --color-badge-owner-bg: rgba(240, 178, 77, 0.18);
    --color-badge-admin-bg: rgba(124, 131, 255, 0.2);
    --color-badge-user-bg: rgba(255, 255, 255, 0.08);
    --color-cover-bg: rgba(23, 26, 32, 0.85);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.55);
}

/* Поля ввода: фон/текст из темы (в светлой теме выглядят как раньше — белые) */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="button"]):not([type="submit"]),
select,
textarea {
    background-color: var(--color-surface);
    color: var(--color-text);
}

:root[data-theme="dark"] ::placeholder {
    color: var(--color-text-muted);
    opacity: 0.7;
}

:root[data-theme="dark"] .btn-secondary:hover {
    background: var(--color-hover);
}

:root[data-theme="dark"] .side-nav-item:hover,
:root[data-theme="dark"] .notif-bell-btn:hover {
    background: var(--color-hover);
}

:root[data-theme="dark"] .toast-close-all {
    color: var(--color-text);
}

:root[data-theme="dark"] .login-form {
    border: 1px solid var(--color-border);
}

:root[data-theme="dark"] img.avatar-sm,
:root[data-theme="dark"] .avatar-lg {
    background: var(--color-skeleton);
}

/* ---- Инлайновые «пастельные» бейджи (статусы работ/станков): светлый фон → тёмный полупрозрачный ----
   Подмена идёт по подстроке в style="…": и в виде hex (серверный HTML), и в виде rgb()
   (когда цвет выставлен из JS через element.style). */
:root[data-theme="dark"] [style*="background:#fdf0d8"],
:root[data-theme="dark"] [style*="background: rgb(253, 240, 216)"] { background: rgba(245, 166, 35, 0.16) !important; }
:root[data-theme="dark"] [style*="background:#e0f5e8"],
:root[data-theme="dark"] [style*="background: rgb(224, 245, 232)"] { background: rgba(46, 158, 91, 0.2) !important; }
:root[data-theme="dark"] [style*="background:#e9ebef"],
:root[data-theme="dark"] [style*="background: rgb(233, 235, 239)"] { background: rgba(148, 163, 184, 0.16) !important; }
:root[data-theme="dark"] [style*="background:#e0edfa"],
:root[data-theme="dark"] [style*="background: rgb(224, 237, 250)"] { background: rgba(74, 144, 217, 0.2) !important; }
:root[data-theme="dark"] [style*="background:#ece5fb"],
:root[data-theme="dark"] [style*="background: rgb(236, 229, 251)"] { background: rgba(125, 95, 214, 0.24) !important; }

:root[data-theme="dark"] [style*="color:#b5720a"],
:root[data-theme="dark"] [style*="color: rgb(181, 114, 10)"] { color: #f0b24d !important; }
:root[data-theme="dark"] [style*="color:#1f7a45"],
:root[data-theme="dark"] [style*="color: rgb(31, 122, 69)"] { color: #62d596 !important; }
:root[data-theme="dark"] [style*="color:#5b6472"],
:root[data-theme="dark"] [style*="color: rgb(91, 100, 114)"] { color: #aeb7c5 !important; }
:root[data-theme="dark"] [style*="color:#2568ab"],
:root[data-theme="dark"] [style*="color: rgb(37, 104, 171)"] { color: #80baf2 !important; }
:root[data-theme="dark"] [style*="color:#7d5fd6"],
:root[data-theme="dark"] [style*="color: rgb(125, 95, 214)"] { color: #b9a0f6 !important; }
:root[data-theme="dark"] [style*="color:#8a94a6"],
:root[data-theme="dark"] [style*="color: rgb(138, 148, 166)"] { color: #9aa3b5 !important; }
:root[data-theme="dark"] [style*="color:#888"] { color: var(--color-text-muted) !important; }

/* Подсветки секций дашборда станков (rgba-тона ок на тёмном, фон «сделано» берёт --color-bg) */
:root[data-theme="dark"] .dash-section-inprogress { background: rgba(34, 165, 90, 0.1); }
:root[data-theme="dark"] .dash-section-planned { background: rgba(124, 131, 255, 0.1); }

/* Блок выбора темы в профиле */
.theme-options {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.theme-option {
    flex: 1 1 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 8px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
}

.theme-option:hover {
    border-color: var(--color-border-strong);
}

.theme-option.is-active {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}

.theme-swatch {
    width: 100%;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 1px solid #d0d4da;
}

.theme-swatch-light { background: linear-gradient(135deg, #f5f6f8 50%, #ffffff 50%); }
.theme-swatch-dark { background: linear-gradient(135deg, #0e1013 50%, #171a20 50%); border-color: #3a414d; }
.theme-swatch-auto { background: linear-gradient(135deg, #f5f6f8 50%, #171a20 50%); }


/* =====================================================================
   «ГОСТ» интерфейса: единые размеры кнопок и полей, шапка страницы, строка поиска.
   Высота всех кнопок и полей — 36px, одинаковые скругления и боковые отступы.
   ===================================================================== */

:root {
    --control-h: 36px;
    --side-btn-w: 96px;   /* ширина кнопок «Добавить» и «Найти» на мобильном — чтобы стояли друг под другом */
}

.btn {
    height: var(--control-h) !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    padding-left: 16px !important;
    padding-right: 16px !important;
    box-sizing: border-box;
    line-height: 1;
    font-size: 13px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    white-space: nowrap;
}

/* Квадратная кнопка-иконка того же размера, что и обычная кнопка */
.btn-icon {
    width: var(--control-h) !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    flex: 0 0 var(--control-h);
}

.btn-icon::before {
    content: "";
    display: block;
    width: 17px;
    height: 17px;
    background-color: currentColor;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: contain;
    mask-size: contain;
}

.btn-icon.is-active {
    background: var(--color-primary-soft);
    border-color: var(--color-primary);
    color: var(--color-link);
}

.btn-icon-print::before {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 6 2 18 2 18 9'/%3E%3Cpath d='M6 18H4a2 2 0 01-2-2v-5a2 2 0 012-2h16a2 2 0 012 2v5a2 2 0 01-2 2h-2'/%3E%3Crect x='6' y='14' width='12' height='8'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 6 2 18 2 18 9'/%3E%3Cpath d='M6 18H4a2 2 0 01-2-2v-5a2 2 0 012-2h16a2 2 0 012 2v5a2 2 0 01-2 2h-2'/%3E%3Crect x='6' y='14' width='12' height='8'/%3E%3C/svg%3E");
}

.btn-icon-grid::before {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='7' height='7'/%3E%3Crect x='14' y='3' width='7' height='7'/%3E%3Crect x='14' y='14' width='7' height='7'/%3E%3Crect x='3' y='14' width='7' height='7'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='7' height='7'/%3E%3Crect x='14' y='3' width='7' height='7'/%3E%3Crect x='14' y='14' width='7' height='7'/%3E%3Crect x='3' y='14' width='7' height='7'/%3E%3C/svg%3E");
}

.btn-icon-list::before {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='8' y1='6' x2='21' y2='6'/%3E%3Cline x1='8' y1='12' x2='21' y2='12'/%3E%3Cline x1='8' y1='18' x2='21' y2='18'/%3E%3Cline x1='3' y1='6' x2='3.01' y2='6'/%3E%3Cline x1='3' y1='12' x2='3.01' y2='12'/%3E%3Cline x1='3' y1='18' x2='3.01' y2='18'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='8' y1='6' x2='21' y2='6'/%3E%3Cline x1='8' y1='12' x2='21' y2='12'/%3E%3Cline x1='8' y1='18' x2='21' y2='18'/%3E%3Cline x1='3' y1='6' x2='3.01' y2='6'/%3E%3Cline x1='3' y1='12' x2='3.01' y2='12'/%3E%3Cline x1='3' y1='18' x2='3.01' y2='18'/%3E%3C/svg%3E");
}

.btn-icon-edit::before {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7'/%3E%3Cpath d='M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7'/%3E%3Cpath d='M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z'/%3E%3C/svg%3E");
}

.btn-icon-delete::before {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18'/%3E%3Cpath d='M8 6V4a2 2 0 012-2h4a2 2 0 012 2v2'/%3E%3Cpath d='M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6'/%3E%3Cline x1='10' y1='11' x2='10' y2='17'/%3E%3Cline x1='14' y1='11' x2='14' y2='17'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18'/%3E%3Cpath d='M8 6V4a2 2 0 012-2h4a2 2 0 012 2v2'/%3E%3Cpath d='M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6'/%3E%3Cline x1='10' y1='11' x2='10' y2='17'/%3E%3Cline x1='14' y1='11' x2='14' y2='17'/%3E%3C/svg%3E");
}

/* Поля ввода и селекты в строках поиска/фильтров — та же высота, что у кнопок */
.search-row input[type="text"],
.search-row input[type="search"],
.search-row select,
.input-std {
    height: var(--control-h);
    box-sizing: border-box;
    padding: 0 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
}

/* Селект: своя стрелка с нормальными отступами вместо системной */
select.input-std,
.search-row select {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 34px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa3b2' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px 12px;
}

/* Шапка страницы: заголовок слева, кнопка действия справа (всегда в одну строку) */
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.page-head h1 {
    margin: 0;
    min-width: 0;
    overflow-wrap: anywhere;
}

.page-head-actions {
    display: flex;
    gap: var(--space-2);
    align-items: center;
    flex-shrink: 0;
}

.page-head .btn,
.page-head-actions .btn,
.list-toolbar .btn:not(.btn-icon) {
    width: auto;
}

/* Строка поиска: [поле][Найти][фильтр]. На мобильном: поле тянется, «Найти» справа
   и по ширине совпадает с кнопкой «Добавить» (стоит строго под ней), фильтр — ниже на всю ширину. */
.search-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
    max-width: 800px;
}

.search-row .search-with-clear {
    display: block;
    flex: 0 1 320px;
    min-width: 0;
}

.search-row .search-with-clear input,
.search-row > input {
    width: 100%;
}

.search-row > input[type="text"] {
    flex: 0 1 320px;
    min-width: 0;
}

.search-row .btn-find {
    width: 80px;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

@media (max-width: 640px) {
    .page-head .btn {
        width: var(--side-btn-w);
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .page-head .page-head-actions .btn-icon {
        width: var(--control-h);
    }

    .search-row {
        max-width: none;
    }

    .search-row .search-with-clear,
    .search-row > input[type="text"] {
        flex: 1 1 0;
    }

    .search-row .btn-find {
        width: var(--side-btn-w);
    }

    .search-row select {
        order: 3;
        flex: 1 1 100%;
        width: 100%;
    }
}


/* ===== Мобильные правки: бейдж роли не растягивается, кнопки разделов ===== */
.info-row > .badge {
    flex: 0 0 auto !important;
    align-self: center;
    margin-left: auto;
}

@media (max-width: 640px) {
    .info-row > span:not(.info-label):not(.icon-btn-group):not(.badge) {
        flex: 1 1 140px;
        text-align: right;
    }

    .section-card {
        padding-left: 0;
        padding-right: 0;
        text-align: center;
    }
}

/* ===== Сессии (устройства) в профиле ===== */
.session-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.session-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    min-width: 0;
}

.session-item.is-current {
    border-color: var(--color-success);
    background: rgba(34, 165, 90, 0.07);
}

.session-icon {
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

.session-item.is-current .session-icon {
    color: var(--color-success);
}

.session-body {
    min-width: 0;
    flex: 1;
}

.session-title {
    font-size: 14px;
    font-weight: 600;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.session-meta {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 2px;
}

.session-current-badge {
    background: rgba(34, 165, 90, 0.16);
    color: var(--color-success);
    font-weight: 600;
}


/* Панель под поиском: слева «действие» (Категории / Все станки), справа переключатель вида */
.list-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.list-toolbar-views {
    display: flex;
    gap: var(--space-2);
    margin-left: auto;
}

@media (max-width: 640px) {
    .list-toolbar .btn:not(.btn-icon) {
        flex: 1 1 auto;
    }
}

/* ===== Список заказов: 2 строки на заказ ===== */
.work-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.work-row {
    display: block;
    padding: 10px 14px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    text-decoration: none;
    color: var(--color-text);
    min-width: 0;
}

.work-row:hover {
    border-color: var(--color-border-strong);
    box-shadow: var(--shadow-sm);
}

.work-row-top {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
}

.work-num {
    font-weight: 700;
    font-size: 14px;
    white-space: nowrap;
}

.work-deadline {
    font-size: 12.5px;
    color: var(--color-text-muted);
    white-space: nowrap;
}

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

.work-status {
    margin-left: auto;
    flex-shrink: 0;
}

.work-row-title {
    display: block;
    margin-top: 4px;
    font-size: 13.5px;
    color: var(--color-text-muted);
    overflow-wrap: anywhere;
}


/* ===== Карточка заказа: статус, действия, этапы, чек-этапы ===== */

/* Квадратная кнопка с текстом внутри (стрелки ▲▼) — тот же размер, что и кнопка-иконка */
.btn-sq {
    width: var(--control-h) !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    flex: 0 0 var(--control-h);
    font-size: 12px;
}

/* Кнопка с иконкой принтера перед текстом */
.btn-print::before {
    content: "";
    display: inline-block;
    width: 15px;
    height: 15px;
    margin-right: 6px;
    background-color: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 6 2 18 2 18 9'/%3E%3Cpath d='M6 18H4a2 2 0 01-2-2v-5a2 2 0 012-2h16a2 2 0 012 2v5a2 2 0 01-2 2h-2'/%3E%3Crect x='6' y='14' width='12' height='8'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 6 2 18 2 18 9'/%3E%3Cpath d='M6 18H4a2 2 0 01-2-2v-5a2 2 0 012-2h16a2 2 0 012 2v5a2 2 0 01-2 2h-2'/%3E%3Crect x='6' y='14' width='12' height='8'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* Плашка статуса: та же высота и скругление, что у кнопок */
.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: var(--control-h);
    padding: 0 14px;
    box-sizing: border-box;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.project-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.project-active-machines {
    font-size: 12.5px;
    color: var(--color-text-muted);
    min-width: 0;
    overflow-wrap: anywhere;
}

.stage-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

/* Этап: 1-я строка — заголовок, 2-я — все кнопки и статус */
.stage-head {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    min-width: 0;
}

.stage-title {
    min-width: 0;
    overflow-wrap: anywhere;
}

.stage-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.stage-actions .stage-status-select {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 240px;
}

.stage-actions .stage-delete {
    margin-left: auto;
}

/* Чек-этапы: карточки вместо таблицы */
.checkin-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.checkin-item {
    position: relative;
    padding: 10px 12px;
    padding-right: 76px; /* место под кнопки в правом верхнем углу */
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    min-width: 0;
}

.checkin-actions {
    position: absolute;
    top: 8px;
    right: 8px;
}

.checkin-who {
    font-size: 11.5px;
    color: var(--color-text-muted);
}

.checkin-when {
    font-size: 12px;
    color: var(--color-text);
    opacity: 0.85;
    margin-top: 1px;
}

.checkin-stage {
    font-size: 13px;
    font-weight: 600;
    margin-top: 6px;
}

.checkin-text {
    font-size: 13.5px;
    margin-top: 2px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.checkin-empty {
    font-size: 13px;
    color: var(--color-text-muted);
    margin: 0;
}

/* Цена + валюта в одну строку */
.price-row {
    display: flex;
    gap: var(--space-2);
}

.price-row input {
    flex: 1 1 auto;
    min-width: 0;
}

.price-row select {
    flex: 0 0 96px;
}

/* Строка «ссылка слева — кнопка-иконка справа» (Где купить и т.п.) */
.link-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 6px 0;
    border-bottom: 1px solid var(--color-border);
    min-width: 0;
}

.link-row > a {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Ряд кнопок, делящих ширину поровну */
.btn-row {
    display: flex;
    gap: var(--space-2);
}

.btn-row .btn {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-row-3 .btn {
    padding-left: 6px !important;
    padding-right: 6px !important;
    font-size: 12px;
}

/* ===== Файлообменник: шапка папки и таблица файлов без горизонтального скролла ===== */
.folder-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    min-width: 0;
}

.folder-head h1 {
    margin: 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.folder-actions {
    flex-shrink: 0;
}

.folder-actions .btn {
    flex: 0 0 auto;
}

.files-table {
    table-layout: fixed;
    width: 100%;
}

.files-table th:nth-child(1),
.files-table td:nth-child(1) { width: 48px; }
.files-table th:nth-child(3),
.files-table td:nth-child(3) { width: 84px; }
.files-table th:nth-child(5),
.files-table td:nth-child(5) { width: 78px; }

.files-table .file-name-cell {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.files-table td:nth-child(4) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 640px) {
    .folder-head {
        flex-wrap: wrap;
    }

    .folder-actions {
        flex: 1 1 100%;
    }

    .folder-actions .btn {
        flex: 1 1 0;
    }

    /* «Загрузил» на узком экране прячем — чтобы название файла не схлопывалось */
    .files-table th:nth-child(4),
    .files-table td:nth-child(4) {
        display: none;
    }

    .files-table th:nth-child(3),
    .files-table td:nth-child(3) { width: 68px; }
}

/* Заметки в карточке пользователя: текст слева, кнопка удаления справа */
.note-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 8px 0;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    min-width: 0;
}

.note-body {
    flex: 1 1 auto;
    min-width: 0;
    text-align: left;
    overflow-wrap: anywhere;
}


/* ===== Фиксы: текст в кнопках, селекты ===== */

/* Кнопка — всегда flex-контейнер с центрированием, даже если где-то остался инлайновый display:block/inline-block */
.btn,
.btn[style*="display:inline-block"],
.btn[style*="display: inline-block"],
.btn[style*="display:block"],
.btn[style*="display: block"],
.btn[style*="display:inline"],
.btn[style*="display: inline"] {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.btn[hidden],
.btn[style*="display:none"],
.btn[style*="display: none"] {
    display: none !important;
}

/* Кнопки-иконки и квадраты не должны ломаться, когда JS ставит им display */
.icon-btn[style*="display:inline;"],
.icon-btn[style*="display: inline;"] {
    display: inline-flex !important;
}

/* Все выпадающие списки: своя стрелка и отступ справа от неё (раньше только у части селектов) */
select:not([multiple]):not([size]) {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 36px !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa3b2' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 13px center;
    background-size: 12px 12px;
    text-overflow: ellipsis;
}

/* Поля формы и селекты одной высоты (в т.ч. цена + валюта) */
.field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="color"]),
.field select {
    height: 40px;
    box-sizing: border-box;
    padding-top: 0;
    padding-bottom: 0;
}

.field textarea {
    box-sizing: border-box;
}

.price-row input,
.price-row select {
    height: 40px !important;
    margin-top: 6px;
}

.price-row select {
    flex: 0 0 104px;
}

/* Селекты со статусом, окрашенные инлайном через background-color, сохраняют стрелку */
select[style*="background:"] {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa3b2' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 13px center !important;
    background-size: 12px 12px !important;
}

.muted-note {
    font-size: 13px;
    color: var(--color-text-muted);
    margin: 0;
}

/* ===== Склад: карточка позиции ===== */
.stock-head {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    min-width: 0;
    margin-bottom: var(--space-4);
}

.stock-qty {
    flex: 0 0 auto;
    text-align: center;
    background: var(--color-bg);
    border: 2px solid var(--color-primary);
    border-radius: var(--radius-md);
    padding: 8px 18px;
    min-width: 80px;
}

.stock-qty-num {
    font-size: 32px;
    font-weight: 700;
    line-height: 1;
    color: var(--color-link);
}

.stock-qty-label {
    font-size: 10.5px;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
    margin-top: 2px;
}

.stock-title {
    flex: 1 1 auto;
    min-width: 0;
}

.stock-title h1 {
    margin: 0;
    overflow-wrap: anywhere;
}

.stock-title p {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--color-text-muted);
}

.stock-delete {
    margin-left: auto;
    align-self: flex-start;
}

/* Кнопки операций — отдельный блок с отступами сверху и снизу от соседних блоков */
.stock-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: 0 0 var(--space-5);
}

@media (max-width: 640px) {
    .stock-head {
        gap: var(--space-3);
    }

    .stock-qty {
        padding: 6px 12px;
        min-width: 64px;
    }

    .stock-qty-num {
        font-size: 26px;
    }

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

    .stock-actions .btn {
        width: 100%;
    }
}

/* Шапка карточки с несколькими действиями: заголовок может занять всю строку, действия переносятся под него */
.page-head.wrap {
    flex-wrap: wrap;
}

.page-head.wrap h1 {
    flex: 1 1 180px;
}

/* Кнопка «Комментарии» (page-side-toggle): только на мобильном (≤900px). */
.btn.page-side-toggle {
    display: none !important;
}

@media (max-width: 900px) {
    .btn.page-side-toggle {
        display: inline-flex !important;
        width: 100%;
        margin-bottom: 16px;
    }
}
