:root {
    --navy: #071a33;
    --navy-soft: #102b4d;
    --gold: #c7a84d;
    --gold-light: #e0c76d;
    --blue: #1677d2;
    --blue-soft: #eaf4ff;
    --background: #f3f6fa;
    --card: #ffffff;
    --text: #132238;
    --muted: #75849a;
    --border: #e2e8f0;
    --danger: #d83a3a;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    background: var(--background);
    color: var(--text);
    font-family:
        Arial,
        "Noto Sans Hebrew",
        sans-serif;
}

body {
    overscroll-behavior: none;
}

button,
input {
    font: inherit;
}

button {
    touch-action: manipulation;
}

.app {
    width: 100%;
    max-width: 720px;
    min-height: 100vh;
    margin: 0 auto;
    padding-bottom: 110px;
    background: var(--background);
}

.topbar {
    padding:
        calc(18px + env(safe-area-inset-top))
        20px
        22px;

    text-align: center;
    color: white;

    background:
        linear-gradient(
            145deg,
            #06172d 0%,
            #0a2343 100%
        );

    border-bottom:
        3px solid var(--gold);
}

.brand {
    margin-bottom: 12px;
    color: var(--gold-light);
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 0.3px;
}

.topbar h1 {
    margin: 0;
    font-size: 27px;
    font-weight: 800;
}

.topbar p {
    margin: 7px 0 0;
    color: #cbd5e1;
    font-size: 14px;
}

.controls {
    padding: 16px 14px 8px;
}

.search-box {
    height: 50px;
    display: flex;
    align-items: center;
    gap: 10px;

    padding: 0 16px;

    background: white;
    border: 1px solid var(--border);
    border-radius: 16px;

    box-shadow:
        0 4px 14px rgba(15, 35, 60, 0.05);
}

.search-icon {
    color: var(--muted);
    font-size: 24px;
    line-height: 1;
}

.search-box input {
    width: 100%;
    height: 100%;

    border: 0;
    outline: 0;
    background: transparent;

    color: var(--text);
    font-size: 16px;
}

.search-box input::placeholder {
    color: #9aa7b8;
}

.selection-bar {
    margin-top: 10px;
    padding: 9px 12px;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;

    background: var(--blue-soft);
    border-radius: 12px;

    color: var(--blue);
    font-size: 14px;
}

.selection-bar button {
    padding: 7px 10px;

    border: 0;
    border-radius: 9px;

    background: white;
    color: var(--blue);

    cursor: pointer;
}

.group-list {
    padding: 4px 14px 16px;

    display: flex;
    flex-direction: column;
    gap: 9px;
}

.group-row {
    min-height: 76px;

    display: flex;
    align-items: center;
    gap: 12px;

    padding: 10px 12px;

    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;

    box-shadow:
        0 3px 12px rgba(20, 40, 70, 0.045);

    transition:
        border-color 140ms ease,
        background 140ms ease,
        transform 140ms ease;
}

.group-row.selected {
    background: var(--blue-soft);
    border-color: #8bc3f4;
}

.select-button {
    width: 23px;
    height: 23px;
    flex: 0 0 23px;

    padding: 0;

    border: 2px solid #b8c4d3;
    border-radius: 7px;

    background: white;
    cursor: pointer;
}

.group-row.selected .select-button {
    position: relative;

    border-color: var(--blue);
    background: var(--blue);
}

.group-row.selected .select-button::after {
    content: "";
    position: absolute;

    width: 8px;
    height: 4px;

    top: 6px;
    left: 5px;

    border-left: 2px solid white;
    border-bottom: 2px solid white;

    transform: rotate(-45deg);
}

.group-avatar {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;

    display: grid;
    place-items: center;

    border-radius: 50%;

    background:
        linear-gradient(
            145deg,
            #f7e8a6,
            #c8a94e
        );

    color: var(--navy);
    font-size: 15px;
    font-weight: 800;

    border: 2px solid #ead889;
}

.group-info {
    min-width: 0;
    flex: 1;

    display: flex;
    flex-direction: column;
    gap: 5px;
}

.group-info strong {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;

    font-size: 16px;
    font-weight: 750;
}

.group-info span {
    color: var(--muted);
    font-size: 13px;
}

.drag-handle {
    width: 42px;
    height: 44px;
    flex: 0 0 42px;

    display: grid;
    place-items: center;

    padding: 0;

    border: 0;
    background: transparent;

    color: #77869a;
    font-size: 23px;

    cursor: grab;
}

.drag-handle:active {
    cursor: grabbing;
}

.empty-state {
    margin: 50px 20px;
    text-align: center;

    color: var(--muted);
    font-size: 15px;
}

.bottom-actions {
    position: fixed;

    right: 0;
    bottom: 0;
    left: 0;

    z-index: 20;

    max-width: 720px;
    margin: 0 auto;

    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;

    padding:
        12px
        14px
        calc(12px + env(safe-area-inset-bottom));

    background:
        rgba(243, 246, 250, 0.96);

    border-top: 1px solid var(--border);

    backdrop-filter: blur(12px);
}

.action-button {
    min-height: 52px;

    border-radius: 14px;

    font-size: 15px;
    font-weight: 800;

    cursor: pointer;
}

.action-button.secondary {
    border: 1px solid #aebac8;
    background: white;
    color: #405268;
}

.action-button.danger {
    border: 1px solid #efb0b0;
    background: #fff5f5;
    color: var(--danger);
}

.action-button:disabled {
    opacity: 0.42;
    cursor: default;
}

.hidden {
    display: none !important;
}

@media (min-width: 721px) {
    body {
        padding: 24px 0;
    }

    .app {
        min-height: calc(100vh - 48px);
        border-radius: 22px;
        overflow: hidden;

        box-shadow:
            0 15px 45px rgba(8, 25, 48, 0.12);
    }

    .bottom-actions {
        bottom: 24px;
        border-radius: 0 0 22px 22px;
    }
}

/* Visual drag & multi-group drag */

body.drag-active {
    user-select: none;
    -webkit-user-select: none;
    cursor: grabbing;
}

.drag-handle {
    touch-action: none;
}

.group-row.drag-source {
    opacity: 0.18;
    transform: scale(0.98);
}

.group-row.drag-source-multi {
    opacity: 0.12;
}

.drag-placeholder {
    min-height: 76px;
    border: 2px dashed var(--blue);
    border-radius: 16px;
    background: var(--blue-soft);
    transition:
        height 160ms ease,
        transform 160ms ease;
}

.drag-placeholder.multi {
    display: flex;
    align-items: center;
    justify-content: center;

    min-height: 82px;

    color: var(--blue);
    font-size: 14px;
    font-weight: 800;
}

.drag-placeholder.multi::after {
    content: attr(data-count) " קבוצות יעברו לכאן";
}

.drag-floating {
    position: fixed;
    z-index: 1000;

    pointer-events: none;

    margin: 0;

    border: 1px solid #8bc3f4;
    border-radius: 16px;

    background: white;

    box-shadow:
        0 18px 42px rgba(7, 26, 51, 0.24);

    transform:
        scale(1.035)
        rotate(-0.4deg);

    transition:
        box-shadow 120ms ease,
        transform 120ms ease;
}

.drag-floating.multi::after {
    content: attr(data-drag-count);

    position: absolute;
    top: -10px;
    left: -8px;

    min-width: 30px;
    height: 30px;

    display: grid;
    place-items: center;

    padding: 0 8px;

    border: 2px solid white;
    border-radius: 999px;

    background: var(--blue);
    color: white;

    font-size: 13px;
    font-weight: 800;

    box-shadow:
        0 5px 14px rgba(22, 119, 210, 0.28);
}

.group-row {
    will-change: transform;
}

/* Prevent text selection while managing groups */
.group-list,
.group-row,
.group-row * {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Prevent long-press text selection across management controls */
.selection-bar,
.selection-bar *,
.bottom-actions,
.bottom-actions *,
.topbar,
.topbar * {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}
