/* CRM 4dog — стиль Gmail / NetHunt */
:root {
    --bg: #fff;
    --bg-secondary: #f8f9fa;
    --bg-hover: #f1f3f4;
    --card: #fff;
    --text: #202124;
    --text-secondary: #5f6368;
    --muted: #5f6368;
    --primary: #1a73e8;
    --primary-hover: #1765cc;
    --sidebar-bg: #fafafa;
    --sidebar-text: #3c4043;
    --sidebar-active-bg: #e8eaed;
    --sidebar-active-accent: #1a73e8;
    --border: #dadce0;
    --danger: #d93025;
    --radius: 4px;
    --radius-pill: 16px;
    --shadow: none;
    --font: 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
    /* Статуси — пігулки з крапкою */
    --status-waiting: #1a73e8;
    --status-to-ship: #f9ab00;
    --status-shipped: #34a853;
    --status-done: #188038;
    --status-cancelled: #d93025;
}

* { box-sizing: border-box; }

body {
    font-family: var(--font);
    background: var(--bg-secondary);
    color: var(--text);
    margin: 0;
    min-height: 100vh;
    font-size: 14px;
}

/* ---------- Layout Gmail ---------- */
.layout-gmail {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
.topbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 1rem;
    min-height: 56px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.topbar-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    margin: 0 -8px 0 -4px;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-secondary);
}
.topbar-menu-btn:hover { background: var(--bg-hover); color: var(--text); }
.topbar-menu-icon {
    width: 20px;
    height: 2px;
    background: currentColor;
    box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor;
}
.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
    font-weight: 500;
    margin-right: 0.5rem;
}
.topbar-logo {
    width: 36px;
    height: 36px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
}
.topbar-title { font-size: 1.1rem; }
.topbar-search-wrap {
    flex: 1;
    max-width: 720px;
    display: flex;
    align-items: center;
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 0 1rem;
    height: 46px;
    margin: 0 2rem;
}
.topbar-search-icon { color: var(--muted); margin-right: 0.5rem; font-size: 1.1rem; }
.topbar-search {
    flex: 1;
    border: none;
    background: transparent;
    font: inherit;
    font-size: 1rem;
    outline: none;
}
.topbar-search::placeholder { color: var(--muted); }
.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.topbar-status {
    font-size: 0.75rem;
    color: var(--muted);
    margin-right: 0.5rem;
}
.topbar-icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--text-secondary);
    text-decoration: none;
}
.topbar-icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.topbar-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Обгортка: сайдбар і основний контент в один ряд — не перетинаються */
.layout-body {
    display: flex;
    flex-direction: row;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.layout-gmail .layout-main {
    display: flex;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}
.sidebar-gmail {
    width: 256px;
    min-width: 256px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    border-right: 1px solid var(--border);
    padding: 0.5rem 0;
    flex-shrink: 0;
    overflow-y: auto;
}
.sidebar-gmail .sidebar-nav { padding: 0; }
.sidebar-gmail .sidebar-link {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1.5rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 0 24px 24px 0;
    margin: 0 0.5rem;
    transition: background .15s;
    font-size: 0.875rem;
}
.sidebar-gmail .sidebar-link:hover {
    background: var(--bg-hover);
}
.sidebar-gmail .sidebar-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-accent);
    font-weight: 500;
}
.sidebar-gmail .sidebar-icon {
    font-size: 1.25rem;
    opacity: 0.85;
    width: 1.25em;
    text-align: center;
}
.layout-gmail .layout-main .main { flex: 1; overflow: auto; }

/* Основна область */
.main-gmail {
    background: var(--card);
    padding: 1.5rem 2rem;
    margin: 0;
    max-width: none;
}

/* Хлібні крихти */
.breadcrumbs {
    font-size: 0.8125rem;
    color: var(--muted);
    margin-bottom: 1rem;
}
.breadcrumbs a { color: var(--primary); text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }

/* Заголовок сторінки та тулбар */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}
.page-header h1 {
    margin: 0;
    font-size: 1.375rem;
    font-weight: 400;
    color: var(--text);
}
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.toolbar .input { min-width: 180px; border-radius: 4px; border: 1px solid var(--border); }
.toolbar-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.summary-line { font-size: 0.8125rem; color: var(--muted); margin-bottom: 0.75rem; }
.summary-line strong { color: var(--text); }

/* Кнопки Gmail */
.btn {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1.25rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 500;
}
.btn:hover {
    background: var(--bg-hover);
}
.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: #fff;
}
.btn-danger {
    color: var(--danger);
    border-color: transparent;
}
.btn-danger:hover { background: rgba(217, 48, 37, 0.08); }
.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8125rem;
}
.btn-add { color: var(--primary); background: transparent; border: none; }
.btn-add:hover { background: rgba(26, 115, 232, 0.08); }
.btn-link { background: transparent; border: none; color: var(--primary); }
.btn-link:hover { text-decoration: underline; }
.btn-orange { background: #f9ab00; color: #202124; border-color: #f9ab00; }
.btn-orange:hover { background: #e37400; color: #fff; border-color: #e37400; }

/* Таблиця Gmail */
.table-wrap {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: auto;
}
.table {
    width: 100%;
    min-width: 900px;
    border-collapse: collapse;
}
.table th,
.table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}
.table th {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: none;
    letter-spacing: 0;
    white-space: nowrap;
    background: var(--card);
}
.table tbody tr:hover { background: var(--bg-secondary); }
.table td a { color: var(--primary); text-decoration: none; }
.table td a:hover { text-decoration: underline; }
.table .col-date { width: 120px; }
.table .col-num { width: 4rem; }
.table .col-actions { white-space: nowrap; }
.table .products-cell { max-width: 280px; line-height: 1.4; }

/* Пігулки статусів (Gmail / NetHunt) */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 500;
}
.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}
.badge-waiting { background: #e8f0fe; color: var(--status-waiting); }
.badge-to_ship { background: #fef7e0; color: #b36b00; }
.badge-shipped { background: #e6f4ea; color: var(--status-shipped); }
.badge-done { background: #e6f4ea; color: var(--status-done); }
.badge-cancelled { background: #fce8e6; color: var(--status-cancelled); }

/* Поля вводу */
.input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font: inherit;
    font-size: 0.875rem;
    width: 100%;
    max-width: 100%;
}
.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
}
label {
    display: block;
    margin-top: 0.75rem;
    margin-bottom: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}
label:first-child { margin-top: 0; }
textarea.input { resize: vertical; min-height: 60px; }
.form-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-row .field { flex: 1; min-width: 160px; }
.form-actions { margin-top: 1.25rem; display: flex; gap: 0.5rem; justify-content: flex-end; }
.form-row.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row.two-cols .field { min-width: 0; }
.form-row.three-cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 1rem; }
.form-row.three-cols .field { min-width: 0; }

/* Модальне вікно */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}
.modal[hidden] { display: none; }
.modal-content {
    background: var(--card);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,.12);
    max-width: 560px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
}
.modal-content h2 { margin-top: 0; margin-bottom: 1rem; font-size: 1.25rem; font-weight: 400; }

/* Головна — картки Gmail */
.dashboard h1 { margin-top: 0; font-size: 1.5rem; font-weight: 400; }
.lead { color: var(--muted); margin-bottom: 1.5rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.card {
    background: var(--card);
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    text-decoration: none;
    color: inherit;
    transition: background .15s, border-color .15s;
}
.card:hover {
    background: var(--bg-secondary);
    border-color: var(--border);
}
.card h2 { margin: 0 0 0.5rem; font-size: 1rem; font-weight: 500; color: var(--primary); }
.card p { margin: 0; font-size: 0.875rem; color: var(--text-secondary); }
.muted { color: var(--muted); font-size: 0.875rem; }

/* Товари в формі заявки */
.items-block { margin-top: 1rem; }
.items-block label { margin-bottom: 0.5rem; }
.order-item-row { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; align-items: flex-start; }
.order-item-row .input { flex: 1; }
.order-item-row .input-title { flex: 2; min-width: 0; }
.order-item-row .input-qty { width: 70px; }
.order-item-row .input-price { width: 90px; }
.btn-remove-item { flex-shrink: 0; padding: 0.5rem; color: var(--muted); }
.btn-remove-item:hover { color: var(--danger); }

.hidden { display: none !important; }
.small { font-size: 0.8125rem; }

/* Вікно Нова заявка */
.order-form-full .order-form-window {
    background: var(--card);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,.15);
    width: 100%;
    max-width: 1200px;
    max-height: 95vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.order-form-full .order-form-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.order-form-full .order-form-head .breadcrumbs { margin-bottom: 0.25rem; }
.order-form-full .order-form-head h2 { margin: 0; font-size: 1.25rem; font-weight: 400; }
.order-form-full form { overflow: auto; flex: 1; padding: 1rem 1.5rem; }
.order-form-columns {
    display: grid;
    grid-template-columns: 220px 1fr 280px;
    gap: 1.5rem;
    align-items: start;
}
@media (max-width: 900px) { .order-form-columns { grid-template-columns: 1fr; } }
.order-form-col-contact { min-width: 0; }
.order-form-col-main { min-width: 0; }
.order-form-col-comms { min-width: 0; }
.order-form-block {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
}
.order-form-block-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    font-weight: 500;
    font-size: 0.875rem;
}
.order-form-block label { margin-top: 0.5rem; }
.order-form-block label:first-of-type { margin-top: 0; }
.order-items-table-wrap { overflow: auto; margin-bottom: 0.5rem; }
.order-items-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.order-items-table th,
.order-items-table td { padding: 0.5rem; text-align: left; border-bottom: 1px solid var(--border); }
.order-items-table th { color: var(--text-secondary); font-weight: 500; font-size: 0.75rem; }
.order-items-table .input { padding: 0.4rem 0.5rem; }
.order-items-table .item-sum { white-space: nowrap; color: var(--muted); }
.order-form-footer {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    background: var(--card);
    flex-wrap: wrap;
}
.order-comms-text { min-height: 120px; resize: vertical; }

/* Сторінка заявки */
.order-processing-block { background: var(--sidebar-active-bg); border-left: 4px solid var(--primary); }
.order-detail-value { margin: 0; font-weight: 500; }
.order-profit-val { color: var(--primary); }
.order-detail-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: 0.5rem; }
.order-detail-head h1 { margin: 0; font-size: 1.375rem; font-weight: 400; }
.order-detail-client-name { font-weight: 500; margin: 0 0 0.25rem 0; }
.ttn-block { margin-top: 1rem; }
.ttn-row { display: flex; gap: 0.5rem; align-items: center; }
.ttn-row .ttn-input { flex: 1; }
.comms-log { font-size: 0.8125rem; color: var(--muted); margin-bottom: 0.75rem; max-height: 120px; overflow: auto; }
.comms-log-line { padding: 0.25rem 0; border-bottom: 1px solid var(--border); }
.link-order { color: var(--primary); text-decoration: none; font-weight: 500; }
.link-order:hover { text-decoration: underline; }

/* ---------- Сторінка налаштувань полів заявок ---------- */
.settings-page-title {
    margin: 0 0 1rem 0;
    font-size: 1.375rem;
    font-weight: 400;
}
.settings-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.settings-toolbar-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.settings-add-btn { color: var(--primary); }
.settings-toolbar-options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    margin-left: auto;
}
.settings-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
}
.settings-checkbox input { margin: 0; }
.settings-row-height {
    font-size: 0.875rem;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}
.input-inline { width: auto; min-width: 100px; display: inline-block; }
.settings-columns {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    align-items: start;
}
@media (max-width: 1000px) {
    .settings-columns { grid-template-columns: 1fr; }
}
.settings-column {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    min-height: 200px;
}
.settings-column-head {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}
.settings-groups { display: flex; flex-direction: column; gap: 1rem; }
.settings-group {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}
.settings-group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
    font-weight: 500;
}
.settings-group-actions { display: flex; gap: 0.25rem; }
.settings-fields-list { list-style: none; margin: 0; padding: 0; }
.settings-field {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.8125rem;
}
.settings-field:last-child { border-bottom: none; }
.settings-field:hover { background: var(--bg-secondary); }
.settings-field-drag {
    color: var(--muted);
    cursor: grab;
    font-size: 1rem;
    user-select: none;
}
.settings-field-name { flex: 1; min-width: 0; }
.settings-field-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }
.btn-icon {
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }
.btn-icon-danger:hover { background: #fce8e6; color: var(--danger); }
.settings-field-hidden { opacity: 0.7; }
.settings-field-disabled { opacity: 0.6; }
.settings-dragging { opacity: 0.5; }
.settings-drop-target { outline: 2px dashed var(--primary); outline-offset: 2px; }
.settings-column-title-input, .settings-group-title-input, .settings-field-name-input {
    border: none;
    background: transparent;
    font: inherit;
    padding: 0.2rem 0;
    max-width: 100%;
}
.settings-group-title-input { font-weight: 500; }
.settings-field-name-input { font-size: 0.8125rem; }
.settings-field-name .settings-field-name-input { width: 100%; min-width: 80px; }
.settings-status { margin-bottom: 0.75rem; font-size: 0.875rem; }

/* Глобальний пошук — перенаправлення на сторінки */
#global-search:focus { outline: none; }
/* Згорнутий сайдбар (кнопка меню) */
.sidebar-gmail.sidebar-collapsed {
    width: 0;
    min-width: 0;
    overflow: hidden;
    padding: 0;
    border-right: none;
}
.sidebar-gmail.sidebar-collapsed .sidebar-nav { visibility: hidden; }

@media (max-width: 900px) {
    .topbar-search-wrap { margin: 0 0.5rem; max-width: 200px; }
    .topbar-title { display: none; }
    .sidebar-gmail { width: 72px; min-width: 72px; }
    .sidebar-gmail .sidebar-link span:not(.sidebar-icon) { display: none; }
    .sidebar-gmail .sidebar-link { justify-content: center; padding: 0.5rem; margin: 0 4px; }
}
