* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", "Inter", Arial, sans-serif;
}

body {
    overflow-x: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

img {
    max-width: 100%;
    display: block;
}

.app-layout {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 280px 1fr;
    background: var(--layout-bg);
}

.sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.02);
    z-index: 5;
}

.sidebar-top {
    margin-bottom: 26px;
    padding: 2px 4px 8px;
}

.logo-block {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-image {
    width: 34px;
    height: 34px;
    object-fit: contain;
    flex-shrink: 0;
    opacity: 0.95;
}

.logo-title {
    font-size: 16px;
    font-weight: 800;
    line-height: 1.05;
    letter-spacing: 0.02em;
}

.logo-subtitle {
    font-size: 12px;
    color: var(--muted);
    margin-top: 3px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav-item,
.nav-group-toggle,
.nav-subitem {
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left;
    padding: 12px 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.nav-item:hover,
.nav-group-toggle:hover,
.nav-subitem:hover {
    background: var(--soft-bg);
}

.nav-item.active,
.nav-subitem.active,
.nav-group.open .nav-group-toggle {
    background: color-mix(in srgb, var(--accent) 14%, transparent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 22%, transparent);
}

.nav-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav-arrow {
    color: var(--muted);
    font-size: 13px;
    transition: transform 0.2s ease;
}

.nav-group.open .nav-arrow {
    transform: rotate(180deg);
}

.nav-submenu {
    display: none;
    flex-direction: column;
    gap: 6px;
    padding: 2px 0 2px 10px;
}

.nav-group.open .nav-submenu {
    display: flex;
}

.nav-subitem {
    color: var(--muted);
    padding: 10px 12px;
}

.app-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 18px 18px 18px 0;
}

.topbar {
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 22px;
    margin-left: 18px;
    background: var(--topbar-bg);
    border: 1px solid var(--border);
    border-radius: 18px 18px 0 0;
    backdrop-filter: blur(10px);
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-title {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 0.01em;
}

.theme-toggle {
    border: 1px solid var(--border-strong);
    background: var(--soft-bg);
    color: var(--text);
    padding: 10px 14px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.18s ease;
}

.theme-toggle:hover {
    background: var(--soft-bg-hover);
    border-color: color-mix(in srgb, var(--accent) 35%, var(--border-strong));
}

.user-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 12px;
    background: var(--soft-bg);
    border: 1px solid var(--border);
}

.user-name {
    font-weight: 700;
    font-size: 14px;
}

.logout-link {
    color: var(--muted);
    font-size: 14px;
    transition: color 0.18s ease;
}

.logout-link:hover {
    color: var(--accent);
}

.app-content {
    flex: 1;
    margin-left: 18px;
    background: var(--content-bg);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 22px 22px;
    padding: 30px;
    min-height: calc(100vh - 108px);
}

.page-grid {
    display: grid;
    gap: 28px;
}

.page-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 28px;
}

.inner-card {
    background: var(--inner-card-bg);
    border: 1px solid var(--border);
    box-shadow: none;
}

h2,
h3 {
    letter-spacing: -0.01em;
}

.section-title {
    margin: 0 0 20px 0;
    font-size: 16px;
    font-weight: 700;
}

.button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 16px;
    border-radius: 12px;
    border: 1px solid var(--border-strong);
    background: var(--soft-bg);
    color: var(--text);
    cursor: pointer;
    transition: all 0.18s ease;
}

.button:hover,
.btn:hover {
    background: var(--soft-bg-hover);
}

.button-primary,
.btn-primary {
    background: linear-gradient(180deg, var(--accent-2) 0%, var(--accent) 100%);
    border-color: color-mix(in srgb, var(--accent) 55%, transparent);
    color: #fff;
    box-shadow: 0 10px 20px color-mix(in srgb, var(--accent) 20%, transparent);
}

.button-primary:hover,
.btn-primary:hover {
    filter: brightness(1.03);
}

.btn-small {
    padding: 9px 12px;
    font-size: 13px;
}

.input,
select,
textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    border-radius: 12px;
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.input:focus,
select:focus,
textarea:focus {
    border-color: color-mix(in srgb, var(--accent) 70%, transparent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

.field-label {
    display: block;
    margin-bottom: 10px;
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--soft-bg);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-weight: 600;
    background: var(--soft-bg);
}

tr:last-child td {
    border-bottom: none;
}

.muted {
    color: var(--muted);
}

.hidden {
    display: none !important;
}

/* Header card */
.card-header {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 2px;
}

.card-header-left {
    min-width: 0;
}

.card-header-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* Client card layout */
.client-card-layout {
    display: grid;
    grid-template-columns: 1.25fr 0.95fr;
    gap: 28px;
    align-items: start;
}

.form-stack {
    display: grid;
    gap: 28px;
}

.compact-stack {
    gap: 16px;
}

.two-col-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.inline-form-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: center;
}

.source-link-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 18px;
    align-items: start;
}

.source-link-main {
    min-width: 0;
}

.source-link-main .field-label {
    margin-bottom: 12px;
}

.source-link-main .inline-form-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: center;
}

.source-link-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: flex-start;
    align-self: start;
    padding-top: 30px;
}

.source-link-status {
    margin-top: 14px;
    min-height: 18px;
}

.auto-links-list {
    display: grid;
    gap: 16px;
}

.auto-link-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 18px;
    align-items: center;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--soft-bg);
}

.auto-link-left {
    min-width: 0;
}

.auto-link-label {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 10px;
}

.auto-link-url {
    font-size: 15px;
    line-height: 1.5;
    word-break: break-word;
}

.auto-link-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
}

.soft-input {
    opacity: 0.78;
}

.source-account-note {
    font-size: 13px;
    line-height: 1.45;
    margin-top: -2px;
    margin-bottom: 2px;
}

.checks-row {
    display: flex;
    gap: 20px;
    row-gap: 14px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.check-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: 14px;
}

.telegram-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 12px;
    margin-top: 12px;
}

.status-text {
    font-size: 13px;
}

.status-ok {
    color: var(--success);
}

.status-warn {
    color: var(--warning);
}

.form-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

textarea.input {
    line-height: 1.5;
}

.page-card h2 {
    margin-top: 0;
}

/* Responsive */
@media (max-width: 1200px) {
    .client-card-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 992px) {
    .app-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: relative;
        width: 100%;
        min-width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .app-main {
        padding: 14px;
    }

    .topbar,
    .app-content {
        margin-left: 0;
    }

    .topbar {
        border-radius: 18px 18px 0 0;
    }

    .page-card {
        padding: 24px;
    }
}

@media (max-width: 900px) {
    .source-link-layout,
    .auto-link-row {
        grid-template-columns: 1fr;
    }

    .source-link-actions,
    .auto-link-actions {
        justify-content: flex-start;
        padding-top: 0;
    }
}

@media (max-width: 720px) {
    .two-col-grid,
    .telegram-row,
    .inline-form-row {
        grid-template-columns: 1fr;
    }

    .topbar {
        height: auto;
        padding: 14px 16px;
        flex-direction: column;
        align-items: flex-start;
    }

    .topbar-right {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .app-content {
        padding: 20px;
    }

    .card-header-actions {
        width: 100%;
    }

    .page-grid,
    .form-stack,
    .client-card-layout {
        gap: 22px;
    }

    .page-card {
        padding: 22px;
    }
}

#clientCardForm {
    display: grid;
    gap: 28px;
}

@media (max-width: 720px) {
    #clientCardForm {
        gap: 22px;
    }
}

.dashboard-hero {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
    flex-wrap: wrap;
}

.dashboard-hero-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.dashboard-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
}

.stat-card {
    padding: 22px 24px;
}

.stat-label {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 8px;
}

.stat-value {
    font-size: 30px;
    font-weight: 800;
    line-height: 1;
}

.dashboard-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.dashboard-search {
    min-width: 280px;
    flex: 1;
    max-width: 420px;
}

.dashboard-toolbar-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.dashboard-table-wrap {
    overflow-x: auto;
}

.dashboard-table th,
.dashboard-table td {
    white-space: nowrap;
}

.client-name-cell {
    cursor: pointer;
    user-select: none;
    min-width: 180px;
}

.client-name-main {
    font-weight: 700;
    margin-bottom: 4px;
}

.client-name-sub {
    font-size: 12px;
    color: var(--muted);
    transition: color 0.18s ease;
}

.collect-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 170px;
}

.collect-tag {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--soft-bg);
    border: 1px solid var(--border);
    font-size: 12px;
}

.telegram-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    display: inline-block;
}

.telegram-on {
    background: #22c55e;
    box-shadow: 0 0 0 4px color-mix(in srgb, #22c55e 16%, transparent);
}

.telegram-off {
    background: #ef4444;
    box-shadow: 0 0 0 4px color-mix(in srgb, #ef4444 16%, transparent);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    border: 1px solid var(--border);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-live {
    color: #22c55e;
    background: color-mix(in srgb, #22c55e 10%, transparent);
}

.status-live .status-dot {
    background: #22c55e;
    box-shadow: 0 0 0 4px color-mix(in srgb, #22c55e 14%, transparent);
}

.status-paused {
    color: #f59e0b;
    background: color-mix(in srgb, #f59e0b 10%, transparent);
}

.status-paused .status-dot {
    background: #f59e0b;
    box-shadow: 0 0 0 4px color-mix(in srgb, #f59e0b 14%, transparent);
}

.status-error {
    color: #ef4444;
    background: color-mix(in srgb, #ef4444 10%, transparent);
}

.status-error .status-dot {
    background: #ef4444;
    box-shadow: 0 0 0 4px color-mix(in srgb, #ef4444 14%, transparent);
}

.status-wait {
    color: #60a5fa;
    background: color-mix(in srgb, #60a5fa 10%, transparent);
}

.status-wait .status-dot {
    background: #60a5fa;
    box-shadow: 0 0 0 4px color-mix(in srgb, #60a5fa 14%, transparent);
}

.row-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

@media (max-width: 1280px) {
    .dashboard-stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .dashboard-stats-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-search {
        min-width: 100%;
        max-width: 100%;
    }
}
.dashboard-page {
    display: grid;
    gap: 22px;
}

.dashboard-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.dashboard-top-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 18px;
}

.dashboard-stat-card {
    padding: 20px 20px 18px;
}

.dashboard-stat-label {
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 10px;
}

.dashboard-stat-value {
    font-size: 18px;
    font-weight: 800;
}

.dashboard-stat-value.ok {
    color: #22c55e;
}

.dashboard-stat-value.err {
    color: #ef4444;
}

.dashboard-toolbar {
    display: flex;
    gap: 14px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.dashboard-search {
    width: 320px;
    max-width: 100%;
}

.dashboard-filter-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.dashboard-filter-row .btn.active {
    background: color-mix(in srgb, var(--accent) 16%, transparent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 24%, transparent);
}

.dashboard-table th,
.dashboard-table td {
    white-space: nowrap;
    vertical-align: middle;
}

.dashboard-table td.wrap {
    white-space: normal;
}

.dashboard-client-cell {
    cursor: pointer;
    user-select: none;
    min-width: 170px;
}

.dashboard-client-name {
    font-weight: 700;
    margin-bottom: 4px;
}

.dashboard-client-sub {
    font-size: 12px;
    color: var(--muted);
}

.clickable-id {
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.collect-badges {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    min-width: 180px;
}

.collect-badge {
    padding: 4px 8px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--soft-bg);
    font-size: 12px;
}

.telegram-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.telegram-on {
    background: #22c55e;
    box-shadow: 0 0 0 4px color-mix(in srgb, #22c55e 16%, transparent);
}

.telegram-off {
    background: #ef4444;
    box-shadow: 0 0 0 4px color-mix(in srgb, #ef4444 16%, transparent);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 999px;
    padding: 7px 10px;
    font-size: 12px;
    font-weight: 700;
    border: 1px solid var(--border);
    cursor: pointer;
}

.status-pill:hover {
    filter: brightness(1.06);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-active {
    color: #22c55e;
    background: color-mix(in srgb, #22c55e 10%, transparent);
}

.status-active .status-dot {
    background: #22c55e;
}

.status-collecting {
    color: #60a5fa;
    background: color-mix(in srgb, #60a5fa 10%, transparent);
}

.status-collecting .status-dot {
    background: #60a5fa;
    animation: pulseDot 1.2s infinite;
}

.status-stopped {
    color: #facc15;
    background: color-mix(in srgb, #facc15 10%, transparent);
}

.status-stopped .status-dot {
    background: #facc15;
}

.status-error {
    color: #ef4444;
    background: color-mix(in srgb, #ef4444 10%, transparent);
}

.status-error .status-dot {
    background: #ef4444;
}

@keyframes pulseDot {
    0% { box-shadow: 0 0 0 0 rgba(96,165,250,.55); }
    70% { box-shadow: 0 0 0 8px rgba(96,165,250,0); }
    100% { box-shadow: 0 0 0 0 rgba(96,165,250,0); }
}

.row-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.icon-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
}

.error-row {
    background: rgba(239, 68, 68, 0.12);
}

.system-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.46);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.system-modal {
    width: min(560px, calc(100vw - 32px));
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 22px;
}

.system-modal h3 {
    margin: 0 0 14px 0;
}

.system-modal p {
    margin: 0 0 10px 0;
    line-height: 1.5;
}

.system-modal-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 18px;
}

@media (max-width: 1280px) {
    .dashboard-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .dashboard-stats {
        grid-template-columns: 1fr;
    }

    .dashboard-search {
        width: 100%;
    }
}
 
.project-status-trigger {
    min-width: 180px;
    justify-content: space-between;
    cursor: pointer;
    padding: 7px 12px;
}

.project-status-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.project-status-caret {
    color: var(--muted);
    font-size: 11px;
    margin-left: 10px;
}

.project-status-dropdown {
    position: fixed;
    display: none;
    min-width: 190px;
    background: #101827;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
    padding: 6px;
    z-index: 99999;
}

.project-status-dropdown.open {
    display: block;
}

.project-status-option {
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text);
    text-align: left;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: background .18s ease;
}

.project-status-option:hover {
    background: var(--soft-bg);
}
.quick-range-row{
    display:flex;
    flex-wrap:wrap;
    gap:10px;
    margin-bottom:14px;
}

.quick-range-btn{
    min-height:42px;
}

html[data-theme="dark"] .date-input-dark {
  color-scheme: dark;
  padding-right: 14px;
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 18px 18px;
  background-image: url("data:image/svg+xml;utf8,\
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'>\
<rect x='3' y='4' width='18' height='18' rx='2' ry='2'/>\
<line x1='16' y1='2' x2='16' y2='6'/>\
<line x1='8' y1='2' x2='8' y2='6'/>\
<line x1='3' y1='10' x2='21' y2='10'/>\
</svg>");
}

html[data-theme="dark"] .date-input-dark::-webkit-calendar-picker-indicator {
  opacity: 0;
  cursor: pointer;
}

html[data-theme="dark"] .date-input-dark::-webkit-datetime-edit,
html[data-theme="dark"] .date-input-dark::-webkit-datetime-edit-text,
html[data-theme="dark"] .date-input-dark::-webkit-datetime-edit-month-field,
html[data-theme="dark"] .date-input-dark::-webkit-datetime-edit-day-field,
html[data-theme="dark"] .date-input-dark::-webkit-datetime-edit-year-field {
  color: #ffffff;
}