/* --- MATERIAL DESIGN 3 TOKENS --- */
:root {
    --m3-surface: #ffffff;
    /* M3 Outline color for unselected chips */
    --m3-outline: #79747E;
    --m3-primary: #6750A4;
    /* M3 Secondary Container for selected chips */
    --m3-secondary-container: #E8DEF8;
    --m3-on-secondary-container: #1D192B;
    --m3-surface-variant: #F4F4F4;
    --envelope-yellow: #F1B255;
}

body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: #e5e5e5;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

/* Material Icons Setup */
.material-symbols-outlined {
  font-family: 'Material Symbols Outlined' !important;
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* --- M3 FILTER CHIP (Identical to Flutter) --- */
.m3-chip {
    display: inline-flex;
    align-items: center;
    height: 32px;
    padding-left: 12px;
    padding-right: 8px;
    border: 1px solid var(--m3-outline);
    border-radius: 100px; /* Full pill shape */
    background: var(--m3-surface);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    color: #49454F;
    box-sizing: border-box;
    gap: 0; /* Gaps are handled by the divider margins */
}

.m3-chip:hover {
    background-color: rgba(0, 0, 0, 0.08);
}

.m3-chip.active {
    background-color: var(--m3-secondary-container);
    border-color: transparent;
    color: var(--m3-on-secondary-container);
}

/* The vertical separator inside the chip */
.m3-chip .v-divider {
    width: 1px;
    height: 32px; /* Matches chip height to span top-to-bottom */
    background-color: currentColor;
    opacity: 0.12;
    margin: 0 8px;
}

.m3-chip .chip-icon {
    font-size: 18px !important;
    margin-right: 4px;
}

/* --- M3 SPLIT BUTTON (Submission UI) --- */
.m3-split-button {
    display: inline-flex;
    align-items: center;
    background: var(--m3-surface);
    border: 1px solid var(--m3-outline);
    border-radius: 100px;
    height: 36px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.m3-split-button input {
    border: none !important;
    margin-bottom: 0 !important;
    padding: 0 12px !important;
    height: 100% !important;
    font-size: 13px;
    width: 110px;
    outline: none;
    background: transparent;
}

.m3-split-button .split-action {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    height: 100%;
    cursor: pointer;
    transition: background 0.2s;
}

.m3-split-button .split-action:hover {
    background-color: rgba(0, 0, 0, 0.08);
}

.m3-split-button .v-divider {
    width: 1px;
    height: 20px;
    background-color: var(--m3-outline);
    opacity: 0.12;
}

/* --- STRUCTURAL LAYOUT (RE-RESTORED FULL VERSION) --- */

/* Manila Envelope Aesthetic - Locked to 5x8 Ratio */
.manila-envelope, .manila-envelope-cover {
    background-color: var(--envelope-yellow);
    padding: 20px;
    width: 100%;
    max-width: 450px;
    aspect-ratio: 5 / 8;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: 4px 8px 15px rgba(0,0,0,0.26);
    box-sizing: border-box;
}

/* White Sticker Aesthetic - Inset and Pinning Content to Top */
.white-sticker {
    background-color: white;
    border-radius: 12px;
    border: 1px solid rgba(0,0,0,0.05);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    flex: none;
    width: 85%;
    height: 80%;
    display: flex;
    flex-direction: column;
    justify-content: center; /* Keeps main text centered */
    align-items: center;
    overflow: hidden;
    box-sizing: border-box;
    padding: 32px;
    position: relative; /* Allow children to be pinned */
}

/* White Sticker-Compact */
.white-sticker-compact {
    background-color: white;
    border-radius: 12px;
    border: 1px solid rgba(0,0,0,0.05);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    flex: none;
    width: 85%;
    height: 80%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
}

/* User Tile & Avatar Components */
.user-tile {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
}

.user-avatar-container {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    background-color: #f0f0f0;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid rgba(0,0,0,0.05);
}

.user-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-avatar-placeholder {
    font-size: 14px;
    font-weight: bold;
    color: #999;
}

.user-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
}

.user-display-name {
    font-size: 11px;
    font-weight: 900;
    color: black;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.user-handle {
    font-size: 9px;
    color: #666;
    margin-top: 1px;
    line-height: 1;
}

/* Updated Creator Row centering and alignment */
.creator-list {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    padding-top: 10px;
}

.creator-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    /* Lock the internal alignment to the pipe */
    width: 100%;
}

.creator-role {
    /* Left side of the pipe: fixed width and right-aligned text */
    flex: 0 0 70px;
    text-align: right;
    font-size: 8px;
    font-weight: bold;
    color: #999;
    text-transform: uppercase;
}

.creator-divider {
    color: #eee;
    font-size: 12px;
    flex-shrink: 0;
}

.creator-identity {
    /* Right side of the pipe: takes the remaining space and holds the UserTile */
    flex: 1;
    display: flex;
    justify-content: flex-start;
}

/* Restored Tab Row Formatting logic */
.bg-gray-100 {
    background-color: #f5f5f5;
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    padding-top: 8px;
    padding-bottom: 8px;
}

/* Utility Classes */
.flex-col { display: flex; flex-direction: column; }
.flex-row { display: flex; flex-direction: row; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.h-full { height: 100%; }
.flex-1 { flex: 1; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.p-2 { padding: 8px; }
.p-4 { padding: 16px; }
.py-4 { padding-top: 16px; padding-bottom: 16px; }
.px-4 { padding-left: 16px; padding-right: 16px; }
.py-2 { padding-top: 8px; padding-bottom: 8px; }
.font-bold { font-weight: bold; }
.text-center { text-align: center; }
.text-justify { text-align: justify; }
.text-lg { font-size: 20px; }
.text-sm { font-size: 14px; }
.text-xs { font-size: 12px; }
.text-gray { color: #666; }
.text-white { color: white; }
.bg-white { background-color: white; }
.hidden { display: none; }
.cursor-pointer { cursor: pointer; }

/* Structural utilities */
.aspect-5-8 { aspect-ratio: 5 / 8; }
.aspect-paper { aspect-ratio: 11 / 8.5; }
.stack { position: relative; }
.positioned-fill { position: absolute; top: 0; right: 0; bottom: 0; left: 0; }
.positioned-left { position: absolute; top: 0; bottom: 0; left: 0; }

/* Form Elements */
input {
    width: 100%;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid #ccc;
    border-radius: 12px;
    box-sizing: border-box;
    font-size: 16px;
}

button.btn-primary {
    width: 100%;
    padding: 16px;
    background-color: #808080;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
}

button.btn-primary:hover {
    background-color: #666;
}

button.btn-logout {
    padding: 8px 16px;
    background-color: transparent;
    color: black;
    text-decoration: underline;
    border: none;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
}

a {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

a:hover {
    text-decoration: underline;
}

.error-msg {
    color: #d9534f;
    font-weight: bold;
    margin-top: 8px;
    text-align: center;
}

/* Fanzine Reader & Navigation */
.nav-pill {
    background: white;
    border: 1px solid rgba(0,0,0,0.05);
    border-radius: 50px;
    padding: 8px 16px;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.5px;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    margin-bottom: 10px;
    color: black;
}
.nav-pill:hover { background: #f9f9f9; }

.fanzine-page-img {
    max-width: 100%;
    height: auto;
    border: 1px solid rgba(0,0,0,0.05);
    border-radius: 2px;
    display: block;
    object-fit: contain;
}

/* --- Grid View Layout --- */
.spread-wrapper {
    position: relative;
    width: 100%;
    max-width: 1000px;
    margin: 24px auto;
    aspect-ratio: 11 / 8.5;
}

.spread-paper {
    background-color: white;
    border-radius: 2px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    padding: 3%;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: row;
}

.spread-half {
    flex: 1;
    display: flex;
    height: 100%;
}

.spread-half.left {
    padding-right: 1.5%;
}

.spread-half.right {
    padding-left: 1.5%;
}

.page-wrapper-border {
    border: 1px solid rgba(0,0,0,0.05);
    background-color: white;
    height: 100%;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    aspect-ratio: 5 / 8;
}

.page-wrapper-border img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* --- Header Overlay --- */
.header-envelope-overlay {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

/* Grid & List View Classes */
.reader-list-item {
    margin-bottom: 48px;
}

.spread-container {
    background: white;
    border-radius: 2px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    padding: 24px;
    display: flex;
    width: 100%;
    box-sizing: border-box;
}

.toolbar-container {
    padding: 12px 8px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.toolbar-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    margin: 0 6px;
    background: none;
    border: none;
    padding: 0;
}

.toolbar-icon-wrapper {
    position: relative;
    padding: 10px;
    border-radius: 50%;
    border: 2px solid black;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 4px;
}

.toolbar-btn.active .toolbar-icon-wrapper {
    background-color: rgba(0, 0, 0, 0.1);
}

.toolbar-btn.active.like-btn .toolbar-icon-wrapper {
    border-color: #ff5252;
    background-color: rgba(255, 82, 82, 0.1);
}

.toolbar-btn.active.like-btn .material-symbols-outlined,
.toolbar-btn.active.like-btn .toolbar-label {
    color: #ff5252;
}

.badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background-color: #757575;
    color: white;
    font-size: 9px;
    font-weight: bold;
    border-radius: 50%;
    padding: 2px 5px;
    border: 1px solid white;
}

.toolbar-btn.active .badge {
    background-color: black;
}

.toolbar-btn.active.like-btn .badge {
    background-color: #ff5252;
}

.toolbar-label {
    font-size: 10px;
    color: black;
}

.toolbar-btn.active .toolbar-label {
    font-weight: bold;
}

/* Stats Table Classes */
.stats-table-wrapper {
    width: 100%;
    overflow-x: auto;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

.stats-table th, .stats-table td {
    border: 1px solid #e0e0e0;
    padding: 8px;
    text-align: center;
}

.stats-table th {
    background-color: white;
    color: #546E7A;
    font-weight: bold;
}

.stats-table tr:nth-child(even) td {
    background-color: #fafafa;
}

.stats-table td.highlight {
    font-weight: bold;
    color: #3f51b5; /* indigo */
}

/* Layout Splitter */
.reader-split-layout {
    display: flex;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

.grid-area {
    background-color: #eeeeee;
    overflow-y: auto;
    padding: 24px;
    box-sizing: border-box;
}

.list-area {
    background-color: white;
    overflow-y: auto;
    padding: 24px;
    box-sizing: border-box;
    position: relative;
    border-left: 1px solid #e0e0e0;
}

/* Responsive Desktop Split Layout */
@media (max-width: 900px) {
    .hidden-on-mobile {
        display: none !important;
    }
    .reader-split-layout {
        flex-direction: column;
    }
}

/* Fanzine Header Context Switches */
.fh-sticker-view { display: none; }
.fh-full-view { display: flex; }

/* CSS Context Switch: When grid and list are both open, hide full and show sticker in the grid */
.reader-split-layout:has(.list-area) .grid-area .fh-full-view { display: none !important; }
.reader-split-layout:has(.list-area) .grid-area .fh-sticker-view { display: flex !important; }