/* ============================================
   MAIN STYLESHEET - Import Manifest
   This is the entry point for all global styles

   STRUCTURE:
   1. Base imports (tokens, reset, typography)
   2. Layout imports (sidebar, panels)
   3. Shared component imports (buttons, forms, dialogs, etc)
   4. App-specific styles (below)
   ============================================ */

/* ============================================
   BASE - Always load first
   ============================================ */
@import url('base/tokens.css');
@import url('base/reset.css');
@import url('base/typography.css');

/* ============================================
   LAYOUT
   ============================================ */
@import url('layout/sidebar.css');
@import url('layout/panels.css');
@import url('layout/utilities.css');

/* ============================================
   SHARED COMPONENTS
   ============================================ */
@import url('shared/buttons.css');
@import url('shared/forms.css');
@import url('shared/dialogs.css');
@import url('shared/badges.css');
@import url('shared/cards.css');
@import url('shared/toggles.css');
@import url('shared/icons.css');

/* ============================================
   APP-SPECIFIC STYLES
   These styles are specific to this application
   and don't belong in shared components
   ============================================ */

/* -------------- SIDEBAR LISTS -------------- */
.list {
    display: flex;
    flex-direction: column;
    gap: 0px;
}

.list:first-of-type {
    margin-bottom: 12px;
}

.list-item {
    display: flex;
    gap: 10px;
    padding: 6px 12px;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    position: relative;
    border: 1px solid transparent;
    background: transparent;
    margin: 0;
}

.list-item:hover {
    background: rgba(128,128,128,0.3);
}

.list-item.active {
    background: rgba(16,185,129,0.15);
}

.list-item.active:hover {
    background: rgba(16,185,129,0.2);
}

.list-item-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    color: var(--muted);
    background: color-mix(in srgb, var(--muted) 12%, transparent);
}

.list-item-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.list-item-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.list-item-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    padding-right: 36px;
}

.list-item.has-status-icon .list-item-name {
    padding-right: 52px;
}

.list-item-gear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--text);
    cursor: pointer;
    border-radius: 6px;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.list-item:hover .list-item-gear {
    opacity: 1;
    pointer-events: auto;
    display: flex;
}

.list-item-gear:hover {
    background: var(--hover-bg);
    color: var(--accent);
}

.pin-indicator {
    color: var(--accent);
    font-size: 12px;
    margin-left: 4px;
}

.list-item-details {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
}

.detail-separator {
    opacity: 0.5;
}

.detail-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.detail-muted {
    font-size: 12px;
    color: var(--muted);
}

.list-item-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
}

.list-item-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.list-item-line1 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 15px;
}

.list-item-line2 {
    font-size: 13px;
    line-height: 1.4;
    display: flex;
    align-items: center;
    gap: 8px;
}

.new-docs-count {
    color: var(--accent);
    font-weight: 600;
    font-size: 13px;
}

.stopped-text {
    color: var(--danger);
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
}

.pin-icon {
    display: inline-block;
    vertical-align: top;
    margin-left: 0;
    opacity: 0.9;
}

.stopped-badge {
    color: var(--danger);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    margin-left: 8px;
}

.stopped-icon {
    position: absolute;
    right: 44px;
    top: 50%;
    transform: translateY(-50%);
    flex-shrink: 0;
    z-index: 1;
}

.list-item-dot {
    opacity: 0.6;
    font-size: 14px;
    margin: 0 6px;
}

.list-item-menu {
    opacity: 0;
    font-weight: 900;
    font-size: 16px;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
    transition: opacity 0.15s ease, background-color 0.15s ease;
}

.list-item-menu:hover {
    background: var(--hover-bg);
}

.list-item-menu:focus {
    outline: none;
}

.list-item:hover .list-item-menu {
    opacity: 1;
}

.list-item-simple {
    padding: 10px 12px;
    padding-right: 44px;
}

.list-item-new {
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    padding: 6px 12px;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    min-height: 44px;
}

.list-item-new span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item-new:hover {
    background: var(--hover-bg);
}

.new-printer-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.new-printer-icon svg {
    stroke: white;
}

.section-title {
    font-size: 12px;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
    margin: 16px 0 8px;
    font-weight: 600;
}

/* -------------- MENU -------------- */
.menu {
    position: absolute;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    z-index: 100;
    min-width: 220px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    color: var(--text);
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.menu-item:hover {
    background: var(--hover-bg);
}

.menu-item svg {
    flex-shrink: 0;
    color: var(--muted);
}

.menu-item-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.85;
}

.menu-item-text {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.menu-item-submenu-toggle {
    justify-content: space-between;
}

.menu-item-chevron {
    width: 12px;
    height: 12px;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.menu-help {
    position: relative;
}

.menu-submenu {
    display: none;
    flex-direction: column;
    gap: 2px;
    padding: 6px;
    position: absolute;
    left: calc(100% + 8px);
    top: 0;
    min-width: 260px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 22px rgba(0,0,0,0.2);
    z-index: 120;
}

.menu-submenu.open {
    display: flex;
}

.menu-item-danger {
    color: var(--danger);
}

.menu-item-danger svg {
    color: var(--danger);
}

.menu-item-danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

.menu-item-accent {
    color: var(--accent);
}

.menu-item-accent svg {
    color: var(--accent);
}

.menu-item-accent:hover {
    background: rgba(16, 185, 129, 0.1);
}

.menu-divider {
    height: 1px;
    background: var(--border);
    margin: 6px 6px;
}

/* -------------- TOKEN DISPLAY -------------- */
.token-display {
    background: var(--bg);
    border: 2px dashed var(--accent);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    margin: 20px 0;
}

.token-value {
    font-size: 24px;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    color: var(--accent);
    letter-spacing: 2px;
    margin: 12px 0;
    user-select: all;
}

.token-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 16px;
}

/* -------------- PRINTER HEADER -------------- */
.printer-header {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.properties-panel .printer-header {
    padding: 0;
}

.documents-panel .printer-header {
    position: sticky;
    top: 0;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
    z-index: 5;
}

.printer-header-main {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.printer-header-info {
    flex: 1;
    min-width: 0;
}

.printer-header-title-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.printer-header-title {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
}

.printer-header-details {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 14px;
    color: var(--text);
}

.printer-detail-line {
    display: flex;
    align-items: center;
    gap: 6px;
}

.printer-header-actions {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* -------------- DOCUMENTS -------------- */
.document-item {
    margin: 0 auto 24px;
    text-align: left;
    display: inline-grid;
    grid-template-columns: 28px auto;
    grid-template-rows: auto auto auto;
    align-items: start;
}

.document-content {
    position: relative;
    display: inline-block;
    text-align: left;
}

.document-header {
    grid-column: 2;
    grid-row: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 0;
    padding: 8px 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.document-preview-wrap {
    display: inline-block;
    grid-column: 2;
    grid-row: 2;
}

.document-footer {
    grid-column: 2;
    grid-row: 3;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0 4px;
}

.document-footer-text {
    padding-left: 0;
}

.document-gutter {
    width: 28px;
    display: flex;
    justify-content: center;
    color: var(--muted);
    z-index: 2;
    grid-column: 1;
    align-self: start;
}

.document-gutter-header {
    grid-row: 1;
    padding-top: 8px;
}

.document-gutter-preview {
    grid-row: 2;
    padding-top: 8px;
}

.document-copy-btn {
    flex-shrink: 0;
}

.document-meta-text {
    color: var(--muted);
    font-size: 13px;
    padding-left: 12px;
}

.document-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.document-debug-switch {
    margin: 0;
    gap: 6px;
}

.document-debug-switch .flag-label {
    font-size: 13px;
    color: var(--muted);
}

.document-debug-switch input[type="checkbox"]:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.document-debug-switch input[type="checkbox"]:disabled ~ .flag-label {
    color: var(--muted);
}

.document-error-icon {
    flex-shrink: 0;
}

/* -------------- TOAST -------------- */
.toast-host {
    position: fixed;
    top: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 300;
}

.toast {
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-elev);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    animation: slideIn 0.3s ease;
}

.toast.ok {
    border-color: var(--ok);
    background: color-mix(in srgb, var(--ok) 10%, var(--bg-elev));
}

.toast.warn {
    border-color: var(--warn);
    background: color-mix(in srgb, var(--warn) 10%, var(--bg-elev));
}

.toast.danger {
    border-color: var(--danger);
    background: color-mix(in srgb, var(--danger) 10%, var(--bg-elev));
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* -------------- THEME TOGGLE -------------- */
#themeToggle {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 70;
}

/* -------------- TRANSITIONS -------------- */
* {
    transition: background-color .2s ease, color .2s ease, border-color .2s ease, filter .15s ease, transform .08s ease;
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}

/* -------------- OPERATIONS PANEL -------------- */
.operations-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    padding: 0;
    min-height: 32px;
}

.operations-title-row {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.operations-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.operations-printer-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    line-height: 32px;
}

.operations-separator {
    color: var(--muted);
    user-select: none;
    font-size: 14px;
}

.operations-protocol {
    font-size: 13px;
    color: var(--muted);
    font-weight: 500;
}

.operations-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    font-size: 15px;
}

.info-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.info-label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.info-separator {
    color: var(--muted);
    user-select: none;
}

.operations-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.operations-button-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.operations-button-row .btn {
    justify-content: center;
}

.operations-actions .btn {
    width: 100%;
    justify-content: center;
}

.section-divider {
    height: 1px;
    background: var(--border);
    margin: 12px 0;
}

.danger-zone {
    margin-top: 16px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0px;
    background: transparent;
}

.danger-zone-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
    margin-bottom: 0;
}

.danger-zone-header:hover {
    background: var(--bg);
    border-color: var(--border);
}

.danger-zone-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.danger-zone-icon {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

.danger-zone-chevron {
    width: 16px;
    height: 16px;
    transition: transform 0.2s ease;
}

.danger-zone-chevron.expanded {
    transform: rotate(180deg);
}

.danger-zone-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease;
}

.danger-zone-content.collapsed {
    max-height: 0;
    opacity: 0;
}

.danger-zone-content.expanded {
    max-height: 140px;
    opacity: 1;
}

.danger-zone-content .btn {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.danger-zone-content .btn:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.3);
}

.danger-zone-chevron {
    filter: var(--icon-filter);
}

.danger-zone.expanded {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.35);
}

.danger-zone.expanded .danger-zone-header {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.35);
}

.danger-zone.expanded .danger-zone-title {
    color: #ef4444;
}

.danger-zone.expanded .danger-zone-icon {
    opacity: 1;
}

.flags-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 8px;
    margin-top: 16px;
}

.debug-switch {
    margin-top: 16px;
}

.operations-actions > .flag-switch {
    margin-bottom: 8px;
}

.drawer-control {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    margin-bottom: 4px;
}

.drawer-info {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 0;
}

.drawer-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    width: auto;
}

.drawer-state {
    font-size: 14px;
    color: var(--text);
    width: auto;
}

.drawer-control .btn {
    width: 100%;
}

.buffer-status-ascii {
    margin-bottom: 8px;
    margin-top: 12px;
}

.buffer-header-ascii {
    font-size: 13px;
    color: var(--text);
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.buffer-header-value {
    color: var(--muted);
    padding-right: 4px;
}

.buffer-bar-ascii {
    font-family: 'Courier New', monospace;
    font-size: 14px;
    color: var(--text);
    letter-spacing: 0;
    line-height: 1.2;
}

.buffer-progress-bar {
    width: 100%;
    height: 6px;
    border: 1px solid var(--border);
    background: transparent;
    overflow: hidden;
    box-sizing: border-box;
}

.buffer-progress-fill {
    height: 100%;
    transition: background-color 0.2s ease;
    will-change: width;
}
