/* ═══════════════════════════════════════════════════════════════
   Pack — Industrial / Field Manual Aesthetic
   ═══════════════════════════════════════════════════════════════ */

:root {
    --bg: #fafaf8;
    --text: #1a1a18;
    --gray: #8a8a85;
    --gray-very-light: #f1f1f1;
    --gray-light: #e5e5e2;
    --gray-mid: #c5c5c2;
    --accent: #c45d1a;
    --accent-light: color-mix(in oklab, var(--accent), white 30%);
    --accent-hover: #a34b14;
    --danger: #c44;
    --font: 'IBM Plex Mono', monospace;
    --page-width: 297mm;
    --page-height: 210mm;
    --page-padding: 8mm;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    font-family: var(--font);
    font-size: 11px;
    line-height: 1;
    background: #e8e8e5;
    color: var(--text);
    height: 100%;
}

/* ─── SCREENS ─── */
.screen {
    display: flex;
}

.hidden {
    display: none !important;
}

/* ─── AUTH ─── */
#auth-screen {
    height: 100vh;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.auth-box {
    width: 320px;
    text-align: center;
}

.auth-box h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 4px;
    margin-bottom: 2px;
}

.auth-box .subtitle {
    font-size: 11px;
    color: var(--gray);
    margin-bottom: 32px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.add-item-row input {
    flex: 1;
    border: none;
    background: transparent;
    font-family: var(--font);
    font-size: 10px;
    color: var(--text);
    outline: none;
    padding: 2px 4px;
}

.add-item-row input::placeholder {
    color: var(--gray);
}

#auth-form input {
    display: block;
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 12px;
    border: 1px solid var(--gray-light);
    background: var(--bg);
    font-family: var(--font);
    font-size: 12px;
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
}

#auth-form input:focus {
    border-color: var(--accent);
}

/* ─── BUTTONS ─── */
button {
    font-family: var(--font);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 1px;
    padding: 8px 14px;
    border: 1px solid var(--text);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s;
    text-transform: uppercase;
    white-space: nowrap;
    line-height: 1;
}

button:hover {
    background: var(--text);
    color: var(--bg);
}

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

button.accent:hover {
    background: var(--accent);
    color: var(--bg);
}

button.small {
    padding: 3px 7px;
    font-size: 9px;
}

button.danger {
    border-color: var(--danger);
    color: var(--danger);
}

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

button.active {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text);
}

button.active:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg);
}

button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

.auth-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.auth-actions button {
    flex: 1;
}

.empty-state button {
    margin-top: 8px;
}

.error {
    color: var(--accent);
    font-size: 10px;
    margin-top: 12px;
    min-height: 14px;
}

/* ─── TOOLBAR ─── */
#toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--bg);
    border-bottom: 1px solid var(--gray-light);
    position: sticky;
    top: 0;
    z-index: 100;
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

#list-select {
    font-family: var(--font);
    font-size: 12px;
    padding: 0 10px;
    border: 1px solid var(--text);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    min-width: 160px;
    height: 28px;
}

/* ─── LIST SELECT GROUP & 3-DOTS DROPDOWN ─── */
.list-select-group {
    display: flex;
    align-items: center;
    gap: 0;
}

.list-select-group #list-select {
    border-right: none;
}

.list-menu-wrap {
    position: relative;
}

.list-menu-btn {
    padding-left: 10px;
    padding-right: 10px;
    letter-spacing: 0;
    border-left: 1px solid var(--text);
    min-width: 0;
}

.ctx-menu-dropdown {
    position: absolute;
    top: calc(100% + 2px);
    min-width: 160px;
    background: var(--bg);
    border: 1px solid var(--gray-light);
    box-shadow: 0 4px 16px rgb(0 0 0 / 12%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    padding: 4px 0;
}

.ctx-menu-dropdown.align-left {
    left: 0;
}

.ctx-menu-dropdown.align-right {
    right: 0;
}

.ctx-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 10px;
    letter-spacing: 0.5px;
    text-align: left;
    text-transform: none;
    cursor: pointer;
    white-space: nowrap;
    width: 100%;
    justify-content: flex-start;
}

.ctx-menu-item:hover {
    background: var(--gray-light);
    color: var(--text);
}

.ctx-menu-item.danger {
    color: var(--danger);
    border: none;
}

.ctx-menu-item.danger:hover {
    background: var(--danger);
    color: var(--bg);
}

.ctx-menu-icon {
    font-size: 12px;
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

/* ─── NOTES TOGGLE BUTTON WITH CHECKBOX ─── */
.notes-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.notes-checkbox {
    display: inline-block;
    width: 1em;
    height: 1em;
    border: 1px solid currentcolor;
    background: transparent;
    flex-shrink: 0;
    position: relative;
}

.notes-checkbox.checked::after {
    content: '';
    position: absolute;
    inset: 1px;
    background: currentcolor;
}

/* ─── APP SCREEN ─── */
#app-screen {
    flex-direction: column;
    height: 100vh;
}

/* ─── PAGE CONTAINER ─── */
#page-container {
    flex: 1;
    overflow: auto;
    padding: 20px;
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
}

/* ─── A4 PAGE ─── */
.a4-landscape {
    width: var(--page-width);
    min-height: var(--page-height);
    background: var(--bg);
    border: 2px dashed var(--gray-mid);
    padding: var(--page-padding);
    position: relative;
    box-shadow: 0 2px 20px rgb(0 0 0 / 8%);
    margin: 0 auto;
}

/* ─── GROUPS CONTAINER (columns layout) ─── */
#groups-container {
    display: flex;
    gap: 3mm;
    align-items: flex-start;
    height: 100%;
}

/* ─── COLUMN ─── */
.column {
    display: flex;
    flex-direction: column;
    gap: 3mm;
    min-width: 100px;
    max-width: 200px;
    flex: 1 1 140px;
    min-height: 40px;
}

.column-drop-target {
    min-height: 60px;
    min-width: 40px;
    max-width: 60px;
    flex: 0 0 40px;
    border: 1px dashed var(--gray-mid);
    border-radius: 2px;
    transition:
        border-color 0.2s,
        min-width 0.2s;
}

.column-drop-target:hover {
    border-color: var(--accent);
    min-width: 80px;
}

.column.drag-over {
    background: rgb(196 93 26 / 3%);
    border-radius: 2px;
}

/* ─── GROUP ─── */
.group {
    border: 1px solid var(--gray-light);
    background: var(--bg);
    width: 100%;
    touch-action: none;
}

.group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 6px;
    background: var(--text);
    color: var(--bg);
    cursor: grab;
    gap: 4px;
    touch-action: none;
}

.group-header:active {
    cursor: grabbing;
}

.group-header .group-name {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    flex: 1;
    border: none;
    background: transparent;
    color: var(--bg);
    font-family: var(--font);
    outline: none;
    cursor: grab;
    min-width: 0;
}

.group-header .group-name:focus {
    cursor: text;
    background: rgb(255 255 255 / 10%);
    padding: 0 4px;
}

.group-header .group-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
    position: relative;
}

.group-header button:not(.ctx-menu-item) {
    background: transparent;
    border: none;
    color: var(--bg);
    padding: 2px 5px;
    font-size: 11px;
    letter-spacing: 0;
}

.group-header button:not(.ctx-menu-item):hover {
    color: var(--accent);
    background: transparent;
}

/* ─── ITEMS ─── */
.items-list {
    list-style: none;
    min-height: 20px;
    padding: 2px 0;
}

.item {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 4px;
    padding: 5px 6px;
    border-bottom: 1px solid var(--gray-light);
    cursor: grab;
    font-size: 10px;
    transition: background 0.1s;
    touch-action: none;
}

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

.item:hover {
    background: #f0f0ed;
}

.item:active {
    cursor: grabbing;
}

.item input[type='checkbox'] {
    width: 12px;
    height: 12px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

/* ─── EMPTY GROUP HINT ─── */
.group-empty-hint {
    padding: 6px 8px;
    font-size: 9px;
    color: var(--gray);
    font-style: italic;
    list-style: none;
}

/* ─── CONTENTEDITABLE PLACEHOLDER ─── */
[contenteditable]:empty::before {
    content: attr(placeholder);
    pointer-events: none;
    display: block;
    color: var(--gray);
}

/* ─── ITEM LEFT GROUP ─── */
.item-left {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    flex: 1;
    min-width: 0;
}

.item .item-text {
    flex: 0 0 fit-content;
    min-width: 30px;
    border: none;
    background: transparent;
    font-family: var(--font);
    font-size: 10px;
    color: var(--text);
    outline: none;
    padding: 1px 2px;
    cursor: text;
    word-break: normal;
    white-space: pre-wrap;
}

.item .item-text:focus {
    background: rgb(196 93 26 / 5%);
}

.item.checked .item-text {
    text-decoration: line-through;
    color: var(--gray);
}

.item .item-note {
    flex: 0 0 fit-content;
    min-width: 30px;
    font-size: 9px;
    color: var(--gray);
    font-style: italic;
    cursor: text;
    padding: 1px 2px;
    outline: none;
    word-break: normal;
    white-space: pre-wrap;
}

.item .item-note:focus {
    background: rgb(196 93 26 / 5%);
}

.item .item-note:not(:focus):empty {
    display: none;
}

/* ─── ITEM ACTIONS ─── */

/* Desktop actions: hover-reveal, pointer:fine + >900px only */
.item-actions-desktop {
    display: none;
    gap: 2px;
    flex-shrink: 0;
    align-self: baseline;
    margin-left: auto;
}

.item .item-actions-desktop button {
    opacity: 0;
    border: none;
    color: var(--gray);
    padding: 0 3px;
    font-size: 11px;
    cursor: pointer;
    letter-spacing: 0;
    transition: opacity 0.15s;
}

.item .item-actions-desktop button:hover {
    background: transparent;
}

.item:hover .item-actions-desktop button {
    opacity: 1;
    background: transparent;
}

.item-actions-desktop .item-delete:hover {
    color: var(--danger);
}

/* Note icon: only visible on hover, hidden when note exists */
.item-actions-desktop .item-note-icon {
    opacity: 0;
}

.item-actions-desktop .item-note-icon:hover {
    color: var(--accent);
}

.item:hover .item-actions-desktop .item-note-icon {
    opacity: 0.5;
}

.item:hover .item-actions-desktop .item-note-icon:hover {
    opacity: 1;
}

@media (pointer: fine) and (width >= 901px) {
    .item-actions-desktop {
        display: flex;
    }

    .item-actions-mobile {
        display: none !important;
    }
}

/* Mobile/touch actions: always visible, pointer:coarse or <=900px */
.item-actions-mobile {
    display: none;
    position: relative;
    flex-shrink: 0;
    align-self: baseline;
}

@media (pointer: coarse), (width <= 900px) {
    .item-actions-mobile {
        display: block;
    }

    .item-actions-desktop {
        display: none !important;
    }
}

.item-menu-btn {
    background: transparent;
    border: none;
    color: var(--gray);
    padding: 0 4px;
    font-size: 14px;
    cursor: pointer;
    letter-spacing: 0;
    line-height: 1;
}

.item-menu-btn:hover {
    color: var(--text);
    background: transparent;
}

.item-menu-dropdown {
    position: absolute;
    right: 0;
    top: 100%;
    z-index: 100;
    background: var(--bg);
    border: 1px solid var(--gray-mid);
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 120px;
    box-shadow: 0 4px 12px rgb(0 0 0 / 15%);
}

.item .item-actions-mobile .item-menu-dropdown button {
    border: none;
    text-align: left;
    padding: 4px 8px;
    font-size: 10px;
    cursor: pointer;
    color: var(--text);
    letter-spacing: 0;
}

.item .item-actions-mobile .item-menu-dropdown button:hover {
    background: var(--gray-light);
    color: var(--text);
}

.item .item-actions-mobile .item-menu-dropdown button.danger {
    color: var(--danger);
}

/* ─── ADD ITEM ─── */
.add-item-row {
    display: flex;
    padding: 3px 6px;
    border-top: 1px solid var(--gray-light);
}

/* ─── SORTABLE GHOST ─── */
.sortable-ghost {
    opacity: 0.4;
    background: rgb(196 93 26 / 10%) !important;
}

.sortable-chosen {
    background: var(--bg);
}

/* ─── SORTABLE DRAG HANDLE ─── */
.sortable-drag {
    box-shadow: 0 4px 12px rgb(0 0 0 / 15%);
}

/* ─── EMPTY STATE ─── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 180mm;
    width: 100%;
    color: var(--gray);
    text-align: center;
    gap: 12px;
}

.empty-state .empty-icon {
    font-size: 48px;
    opacity: 0.3;
}

.empty-state h2 {
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.empty-state p {
    font-size: 12px;
    max-width: 280px;
}

/* ─── TOAST ─── */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 10px 16px;
    font-family: var(--font);
    font-size: 11px;
    letter-spacing: 0.5px;
    border: 1px solid transparent;
    max-width: 360px;
    z-index: 9999;
    opacity: 0;
    transform: translateY(8px);
    transition:
        opacity 0.25s ease,
        transform 0.25s ease;
    pointer-events: none;
}

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

.toast-error {
    background: #1a1a18;
    color: #fafaf8;
    border-color: var(--danger);
}

.toast-success {
    background: #1a1a18;
    color: #fafaf8;
    border-color: var(--accent);
}

/* ─── UTILITY ─── */
[x-cloak] {
    display: none !important;
}

/* ─── MODAL ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgb(26 26 24 / 70%);
    display: flex;
    align-items: safe center;
    justify-content: safe center;
    z-index: 200;
}

.modal {
    background: var(--bg);
    border: 1px solid var(--gray-mid);
    padding: 24px;
    width: 480px;
    max-width: calc(100vw - 32px);
    max-height: 100vh;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal h2 {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.modal-hint {
    font-size: 10px;
    color: var(--gray);
}

.import-textarea {
    font-family: var(--font);
    font-size: 10px;
    background: var(--bg);
    border: 1px solid var(--gray-light);
    color: var(--text);
    padding: 10px;
    resize: vertical;
    min-height: 140px;
    width: 100%;
    outline: none;
    transition: border-color 0.2s;
}

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

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.modal-input {
    font-family: var(--font);
    font-size: 11px;
    background: var(--bg);
    border: 1px solid var(--gray-light);
    color: var(--text);
    padding: 8px 10px;
    width: 100%;
    outline: none;
    transition: border-color 0.2s;
}

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

.modal-dialog {
    width: 360px;
}

/* ─── RESPONSIVE ─── */

/* Mobile menu toggle — hidden on desktop */
#menu-toggle {
    display: none;
}

@media (width <= 900px) {
    /* Remove outer padding so dashed border is flush */
    #page-container {
        padding: 0;
        justify-content: flex-start;
        align-items: flex-start;
        overflow: auto;
    }

    /* Keep A4 page scrollable but no outer gap */
    .a4-landscape {
        box-shadow: none;
        border-left: none;
        border-right: none;
        border-top: none;
        padding: 3mm;
    }

    /* Tighten gaps between groups and columns */
    #groups-container {
        gap: 2mm;
    }

    .column {
        gap: 2mm;
    }

    /* Reduce base font */
    html,
    body {
        font-size: 10px;
    }

    /* Tighten toolbar */
    #toolbar {
        padding: 6px 10px;
        flex-wrap: wrap;
        gap: 0;
        position: relative;
    }

    .toolbar-left,
    .toolbar-right {
        gap: 4px;
    }

    /* Shrink list select */
    #list-select {
        min-width: 100px;
        font-size: 9px;
        padding: 0 6px;
        height: 21px;
    }

    /* Tighten buttons */
    button {
        padding: 5px 8px;
        font-size: 9px;
    }

    /* Show menu toggle button — floated to far right of navbar */
    #menu-toggle {
        display: inline-flex;
        align-items: center;
        margin-left: auto;
    }

    /* Toolbar right items collapse into sliding panel */
    .toolbar-right {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--bg);
        border-bottom: 1px solid var(--gray-light);
        padding: 6px 10px;
        flex-wrap: wrap;
        gap: 6px;
        z-index: 99;
        box-shadow: 0 4px 12px rgb(0 0 0 / 10%);
    }

    .toolbar-right.menu-open {
        display: flex;
    }
}

@media (width <= 600px) {
    html,
    body {
        font-size: 9px;
    }

    #toolbar {
        padding: 4px 8px;
    }

    #list-select {
        min-width: 80px;
        max-width: 130px;
        font-size: 9px;
        padding: 0 6px;
        height: 19px;
    }

    button {
        padding: 4px 6px;
        font-size: 9px;
        letter-spacing: 0.5px;
    }
}

/* ─── GROUP MENU ─── */
.btn-shared-indicator {
    cursor: default;
    opacity: 0.75;
    font-size: 10px;
    padding: 2px 4px;
    background: transparent;
}

.btn-shared-indicator:hover {
    color: var(--bg) !important;
    background: transparent !important;
}

.btn-group-menu {
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    padding: 2px 5px;
    letter-spacing: 0;
    background: transparent;
}

/* ─── ADD GROUP MODAL ─── */
.add-group-modal {
    width: 600px;
}

.add-group-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.add-group-divider {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--gray);
    text-align: center;
    padding-top: 12px;
    border-top: 1px solid var(--gray-light);
}

.linkable-groups-list {
    overflow-y: auto;
    border: 1px solid var(--gray-light);
    display: flex;
    flex-direction: column;
}

.linkable-group-item {
    padding: 6px 8px;
    font-size: 10px;
    cursor: pointer;
    border-bottom: 1px solid var(--gray-light);
}

.linkable-group-item:last-of-type {
    border-bottom: none;
}

.linkable-group-item:hover {
    background: var(--gray-light);
}

.linkable-group-item.selected {
    background: var(--gray-very-light);
    outline: 1px solid var(--accent-light);
    outline-offset: -1px;
}

.linkable-group-item-first-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.linkable-group-item-second-row {
    margin-left: 1rem;
    font-size: 9px;
    font-style: italic;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.linkable-group-source {
    font-size: 9px;
    flex-shrink: 0;
}

.linkable-group-source span:last-child,
.linkable-group-item-second-row {
    color: var(--gray);
}

.linkable-group-empty-hint {
    padding: 6px 8px;
    font-size: 9px;
    color: var(--gray);
    font-style: italic;
}
