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

body {
    font-family: Arial, Helvetica, sans-serif;
    background: linear-gradient(135deg, #f5f3ed 0%, #e8e5d9 100%);
    padding: 40px 20px;
}

/* Controls */
.controls {
    max-width: 750px;
    margin: 0 auto 20px;
    display: flex;
    gap: 10px;
    justify-content: center;
}

.btn-print, .btn-edit {
    padding: 12px 24px;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-print {
    background-color: #c94234;
    color: white;
}

.btn-print:hover {
    background-color: #a83529;
}

.btn-edit {
    background-color: #333;
    color: white;
}

.btn-edit:hover {
    background-color: #555;
}

.btn-tv {
    background-color: #2196F3;
    color: white;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-tv:hover {
    background-color: #1976D2;
}

/* Menu Container */
.menu-container {
    max-width: 750px;
    margin: 0 auto;
    background-color: #f5f3ed;
    padding: 30px 40px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

/* Header */
.menu-header {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
}

.header-line {
    flex: 1;
    height: 3px;
    background-color: #c94234;
}

.header-box {
    background-color: #c94234;
    padding: 12px 50px;
    margin: 0 -3px;
}

.header-box h1 {
    color: white;
    font-size: 38px;
    font-weight: bold;
    letter-spacing: 10px;
    text-align: center;
}

/* Main Title */
.main-title {
    font-size: 36px;
    font-weight: 900;
    text-align: center;
    margin-bottom: 15px;
    letter-spacing: 2px;
}

/* Section Styles */
.section {
    margin-bottom: 10px;
}

.section-header {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
    position: relative;
}

.section-header h3 {
    color: #c94234;
    font-size: 18px;
    font-weight: 900;
    margin-right: 10px;
    white-space: nowrap;
}

.section-header span {
    font-size: 16px;
    font-weight: 600;
    margin-right: 15px;
    white-space: nowrap;
}

.section-line {
    flex: 1;
    height: 3px;
    background-color: #c94234;
}

.section-line-small {
    flex: 1;
    height: 3px;
    background-color: #c94234;
    margin-left: 15px;
}

/* Menu Items */
.menu-items {
    margin-bottom: 5px;
}

.menu-item {
    margin-bottom: 6px;
    position: relative;
    padding-right: 30px;
}

.menu-item:hover .btn-delete {
    opacity: 1;
}

.item-header {
    display: flex;
    align-items: baseline;
    margin-bottom: 2px;
}

.item-number {
    font-weight: bold;
    font-size: 14px;
    margin-right: 5px;
    min-width: 20px;
}

.item-name {
    font-weight: bold;
    font-size: 14px;
    white-space: nowrap;
}

.dots {
    flex: 1;
    border-bottom: 2px dotted #aaa;
    margin: 0 8px 3px;
    min-width: 20px;
}

.item-price {
    font-weight: bold;
    font-size: 14px;
    white-space: nowrap;
}

.item-description {
    font-size: 12px;
    color: #333;
    margin-left: 25px;
    line-height: 1.2;
}

/* Simple Menu Items (for Chorizos, Bebidas, Panchos) */
.menu-item-simple {
    margin-bottom: 6px;
    position: relative;
    padding-right: 30px;
}

.menu-item-simple:hover .btn-delete {
    opacity: 1;
}

.simple-header {
    display: flex;
    align-items: baseline;
}

.dots-simple {
    flex: 1;
    border-bottom: 2px dotted #999;
    margin: 0 6px 2px;
    min-width: 20px;
}

.item-description-simple {
    font-size: 11px;
    color: #555;
    margin-left: 20px;
    margin-top: 1px;
    line-height: 1.2;
    min-height: 12px;
}

.item-description-simple:empty:before {
    content: attr(placeholder);
    color: #999;
    font-style: italic;
}

.item-description-simple:focus:before {
    content: '';
}

/* Panchos Layout */
.panchos-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.panchos-layout .simple-header {
    display: flex;
    align-items: baseline;
}

.panchos-layout .item-name {
    white-space: nowrap;
}

.panchos-layout .item-price {
    white-space: nowrap;
    font-size: 13px;
}

/* Bottom Grid */
.bottom-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
    margin-bottom: 8px;
}

/* Overflow Warning */
.overflow-warning {
    position: fixed;
    top: 80px;
    right: 20px;
    background-color: #ff9800;
    color: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    font-weight: bold;
    font-size: 14px;
    animation: pulse 2s infinite;
    max-width: 300px;
}

.overflow-warning::before {
    content: "⚠️ ";
    font-size: 18px;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

.overflow-warning button {
    margin-top: 10px;
    padding: 5px 10px;
    background-color: white;
    color: #ff9800;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

.overflow-warning button:hover {
    background-color: #f0f0f0;
}

/* Footer Note */
.footer-note {
    text-align: right;
    margin-top: 5px;
}

.footer-note p {
    font-size: 14px;
    color: #c94234;
    font-style: italic;
}

/* Buttons */
.btn-add {
    padding: 8px 16px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    margin-top: 10px;
    transition: all 0.3s;
    display: none; /* Hidden by default */
}

.btn-add:hover {
    background-color: #45a049;
}

.btn-delete {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    padding: 4px 8px;
    background-color: #f44336;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.3s;
    display: none; /* Hidden by default */
}

.btn-delete:hover {
    background-color: #da190b;
}

/* Contenteditable Styles */
[contenteditable="true"]:hover {
    background-color: rgba(201, 66, 52, 0.1);
    outline: 1px dashed #c94234;
    border-radius: 2px;
}

[contenteditable="true"]:focus {
    background-color: rgba(201, 66, 52, 0.15);
    outline: 2px solid #c94234;
    border-radius: 2px;
}

/* Edit Mode Styles */
.edit-mode [contenteditable="true"] {
    background-color: rgba(201, 66, 52, 0.05);
    cursor: text;
}

/* Show buttons only in edit mode */
.edit-mode .btn-add {
    display: block;
}

.edit-mode .btn-delete {
    display: block;
}

.edit-mode .menu-item:hover .btn-delete,
.edit-mode .menu-item-simple:hover .btn-delete {
    opacity: 1;
}

/* Hide empty descriptions by default, show in edit mode */
.item-description-simple:empty,
.item-description-simple:empty:before {
    display: none;
}

.edit-mode .item-description-simple:empty,
.edit-mode .item-description-simple:empty:before {
    display: block;
}

/* Show all descriptions in edit mode with placeholder */
.edit-mode .item-description-simple {
    display: block;
    min-height: 14px;
}

/* Visual indicator for edit mode */
.edit-mode {
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.3);
}

/* Print Styles */
@media print {
    @page {
        size: A4 portrait;
        margin: 5mm 8mm;
    }

    * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        color-adjust: exact;
    }

    body {
        background-color: white !important;
        background-image: none !important;
        padding: 0;
        margin: 0;
    }

    .menu-container {
        box-shadow: none;
        padding: 10px 18px;
        max-width: 100%;
        background-color: white !important;
    }

    .no-print {
        display: none !important;
    }

    .btn-delete {
        display: none !important;
    }

    [contenteditable="true"] {
        background-color: transparent !important;
        outline: none !important;
    }

    .menu-item,
    .menu-item-simple {
        padding-right: 0 !important;
    }

    /* Maximized font sizes to fill A4 page */
    .menu-header {
        margin-bottom: 10px;
    }

    .header-line {
        height: 3px;
    }

    .header-box {
        padding: 10px 45px;
    }

    .header-box h1 {
        font-size: 40px;
        letter-spacing: 10px;
    }

    .section-header h3 {
        font-size: 22px;
    }

    .section-header span {
        font-size: 20px;
    }

    .section-line,
    .section-line-small {
        height: 3px;
    }

    .item-number {
        font-size: 16px;
        min-width: 22px;
        margin-right: 6px;
    }

    .item-name {
        font-size: 16px;
    }

    .item-price {
        font-size: 16px;
    }

    .item-description {
        font-size: 14px;
        line-height: 1.35;
        margin-left: 28px;
        margin-top: 2px;
    }

    .item-description-simple {
        font-size: 13px;
        line-height: 1.3;
        margin-left: 25px;
        margin-top: 1.5px;
    }

    .section {
        margin-bottom: 14px;
    }

    .section-header {
        margin-bottom: 7px;
    }

    .menu-item {
        margin-bottom: 6px;
    }

    .menu-item-simple {
        margin-bottom: 5px;
    }

    .item-header {
        margin-bottom: 2px;
    }

    .bottom-grid {
        gap: 10px;
        margin-bottom: 8px;
    }

    .panchos-layout {
        gap: 9px;
    }

    .panchos-layout .item-price {
        font-size: 15px;
    }

    /* Dots optimization for print */
    .dots {
        margin: 0 8px 3px;
    }

    .dots-simple {
        margin: 0 7px 3px;
    }

    /* Ensure proper page breaks */
    .section {
        page-break-inside: avoid;
    }

    .menu-item {
        page-break-inside: avoid;
    }

    .bottom-grid {
        page-break-inside: avoid;
    }

    /* Make background colors print correctly */
    .header-line,
    .section-line,
    .section-line-small {
        background-color: #c94234 !important;
    }

    .header-box {
        background-color: #c94234 !important;
    }

    .header-box h1 {
        color: white !important;
    }

    .section-header h3 {
        color: #c94234 !important;
    }

    .footer-note {
        margin-top: 4px;
    }

    .footer-note p {
        color: #c94234 !important;
        font-size: 14px;
    }

    /* Better text rendering for print */
    * {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeLegibility;
    }
}

/* Mobile Responsive Styles */
@media screen and (max-width: 768px) {
    body {
        padding: 15px 10px;
    }

    /* Mobile-friendly controls */
    .controls {
        display: flex;
        flex-direction: column;
        gap: 10px;
        margin-bottom: 20px;
    }

    .btn-print,
    .btn-edit,
    .btn-tv {
        width: 100%;
        padding: 15px 20px;
        font-size: 16px;
        border-radius: 8px;
        touch-action: manipulation;
    }

    /* Menu container optimized for mobile */
    .menu-container {
        max-width: 100%;
        padding: 20px 15px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    }

    /* Header */
    .menu-header {
        margin-bottom: 15px;
    }

    .header-box h1 {
        font-size: 28px;
        letter-spacing: 4px;
        padding: 8px 20px;
    }

    .header-line {
        height: 2px;
    }

    /* Sections */
    .section {
        margin-bottom: 15px;
    }

    .section-header h3 {
        font-size: 18px;
    }

    .section-header span {
        font-size: 16px;
    }

    .section-line,
    .section-line-small {
        height: 2px;
    }

    /* Items */
    .item-number {
        font-size: 14px;
        min-width: 20px;
    }

    .item-name {
        font-size: 14px;
    }

    .item-price {
        font-size: 14px;
    }

    .item-description {
        font-size: 12px;
        margin-left: 22px;
        line-height: 1.3;
    }

    .item-description-simple {
        font-size: 11px;
        margin-left: 20px;
        line-height: 1.3;
    }

    /* Make bottom grid stack on mobile */
    .bottom-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    /* Keep panchos in 2 columns but smaller */
    .panchos-layout {
        gap: 8px;
    }

    /* Touch-friendly delete buttons */
    .btn-delete {
        padding: 8px 12px;
        font-size: 16px;
        opacity: 0.7;
    }

    .edit-mode .btn-delete {
        opacity: 1;
    }

    /* Touch-friendly add buttons */
    .btn-add {
        font-size: 15px;
        padding: 10px 18px;
    }

    /* Footer */
    .footer-note p {
        font-size: 11px;
    }

    /* Contenteditable touch improvements */
    [contenteditable="true"] {
        cursor: text;
        -webkit-user-select: text;
        user-select: text;
        -webkit-tap-highlight-color: rgba(201, 66, 52, 0.2);
    }

    .edit-mode [contenteditable="true"] {
        min-height: 24px;
        padding: 2px;
    }

    /* Prevent zoom on input focus (iOS) */
    [contenteditable="true"]:focus {
        font-size: 16px;
    }
}

/* Very small mobile screens */
@media screen and (max-width: 480px) {
    body {
        padding: 10px 5px;
    }

    .menu-container {
        padding: 15px 10px;
    }

    .header-box h1 {
        font-size: 24px;
        letter-spacing: 3px;
        padding: 6px 15px;
    }

    .section-header h3 {
        font-size: 16px;
    }

    .section-header span {
        font-size: 14px;
    }

    .item-number,
    .item-name,
    .item-price {
        font-size: 13px;
    }

    .item-description {
        font-size: 11px;
    }

    .item-description-simple {
        font-size: 10px;
    }

    /* Single column for panchos on very small screens */
    .panchos-layout {
        grid-template-columns: 1fr;
    }
}

/* Responsive Design */
@media screen and (max-width: 768px) {
    .menu-container {
        padding: 30px 25px;
    }

    .header-box {
        padding: 15px 40px;
    }

    .header-box h1 {
        font-size: 32px;
    }

    .main-title {
        font-size: 32px;
    }

    .bottom-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .panchos-layout {
        grid-template-columns: 1fr;
    }
}
