* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f5f5f5;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden; /* Container handles overflow, not body */
}

/* Sidebar Controls */
.sidebar {
    width: 280px;
    background: #fff;
    border-right: 2px solid #e0e0e0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
    z-index: 10;
}

.sidebar h1 {
    font-size: 24px;
    color: #2c3e50;
    margin-bottom: 10px;
}

.control-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    width: 100%;
}

.control-left {
    display: flex;
    gap: 8px;
}

.control-right {
    display: flex;
    gap: 8px;
}

.control-group {
    display: flex;
    gap: 8px;
}

.control-group button,
.control-left button,
.control-right button {
    padding: 10px 14px;
    font-size: 16px;
    font-weight: bold;
    border: none;
    background: #3498db;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 40px;
}

.control-group button:hover,
.control-left button:hover,
.control-right button:hover {
    background: #2980b9;
    transform: translateY(-2px);
}

.control-group button:active,
.control-left button:active,
.control-right button:active {
    transform: translateY(0);
}

.file-upload-label {
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 600;
    background: #3498db;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    display: inline-block;
    transition: all 0.2s;
}

.file-upload-label:hover {
    background: #2980b9;
    transform: translateY(-2px);
}

button {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
    background: #3498db;
    color: white;
}

button:hover {
    background: #2980b9;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

button:active {
    transform: translateY(0);
}

button.secondary {
    background: #95a5a6;
}

button.secondary:hover {
    background: #7f8c8d;
}

button.danger {
    background: #e74c3c;
}

button.danger:hover {
    background: #c0392b;
}

.zoom-controls {
    display: flex;
    gap: 10px;
}

.zoom-controls button {
    flex: 1;
    padding: 15px;
    font-size: 18px;
}

input[type="file"] {
    display: none;
}

/* Canvas Area */
.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #ecf0f1;
    touch-action: none;
}

canvas {
    display: block;
    cursor: grab;
    transition: cursor 0.1s ease;
}

canvas:active {
    cursor: grabbing;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: white;
    border-radius: 12px;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 30px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    margin: auto;
    position: relative;
}

.modal-close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: #f8f9fa;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 20px;
    color: #7f8c8d;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    padding: 0;
    line-height: 1;
    z-index: 10;
}

.modal-close-btn:hover {
    background: #e74c3c;
    color: white;
    transform: rotate(90deg);
}

.modal h2 {
    margin-bottom: 20px;
    color: #2c3e50;
    padding-right: 50px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #3498db;
}

.treatments-section {
    margin-top: 30px;
    border-top: 2px solid #eee;
    padding-top: 20px;
}

.treatments-section h3 {
    margin-bottom: 15px;
    color: #2c3e50;
}

.treatment-item {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 10px;
    border-left: 4px solid #3498db;
}

.treatment-date {
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 5px;
}

.treatment-type {
    color: #7f8c8d;
    font-size: 13px;
    margin-bottom: 5px;
}

.treatment-comment {
    color: #555;
    font-size: 14px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-actions button {
    flex: 1;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        overflow: visible; /* Allow scroll on mobile for pull-to-refresh */
    }

    .sidebar {
        width: 100%;
        height: auto;
        max-height: none;
        border-right: none;
        border-bottom: 2px solid #e0e0e0;
        padding: 8px;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
        align-items: center;
        overflow: visible; /* Allow content to be scrollable */
    }

    .sidebar h1 {
        width: 100%;
        font-size: 16px;
        margin-bottom: 3px;
        text-align: left;
    }

    .control-row {
        gap: 8px;
    }

    .control-left,
    .control-right {
        gap: 6px;
    }

    .control-group button,
    .control-left button,
    .control-right button {
        padding: 8px 12px;
        font-size: 14px;
        min-width: 36px;
    }

    .file-upload-label {
        padding: 8px 12px;
        font-size: 13px;
    }

    /* Image upload button - compact on mobile */
    .file-upload-label {
        padding: 8px 10px;
        font-size: 13px;
        white-space: nowrap;
    }

    /* Add square button - compact */
    #addSquareBtn {
        padding: 8px 10px;
        font-size: 13px;
        white-space: nowrap;
    }

    /* Zoom controls - compact */
    .zoom-controls {
        display: flex;
        gap: 4px;
    }

    .zoom-controls button {
        padding: 8px 12px;
        font-size: 16px;
        min-width: 40px;
    }

    /* Action row - buttons left, info right */
    .action-row {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 8px;
    }

    .action-buttons {
        display: flex;
        gap: 4px;
        flex-shrink: 0;
    }

    .action-buttons button {
        padding: 8px 10px;
        font-size: 18px;
        min-width: 40px;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Tooltips for mobile - show on tap/hold */
    .action-buttons button::after {
        font-size: 10px;
        min-width: 120px;
        padding: 5px 8px;
        bottom: 115%;
    }

    .action-buttons button::before {
        bottom: 105%;
    }

    .info-display {
        background: #f8f9fa;
        padding: 6px 10px;
        border-radius: 6px;
        font-size: 10px;
        color: #7f8c8d;
        text-align: right;
        white-space: nowrap;
        flex: 1;
        min-width: 0;
        justify-content: flex-end;
    }

    button {
        padding: 8px 10px;
        font-size: 13px;
    }

    /* Modal improvements for mobile */
    .modal-overlay {
        padding: 30px;
        align-items: flex-start;
        padding-top: 40px;
        padding-bottom: 120px;
    }

    .modal {
        padding: 20px;
        max-height: calc(100vh - 160px);
        margin: 0;
        width: 100%;
        border-radius: 12px;
    }

    .modal-close-btn {
        top: 12px;
        right: 12px;
        width: 32px;
        height: 32px;
        font-size: 18px;
    }

    .modal h2 {
        font-size: 20px;
        margin-bottom: 15px;
        padding-right: 45px;
    }

    .form-group {
        margin-bottom: 15px;
    }

    .form-group input,
    .form-group textarea,
    .form-group select {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px;
    }

    .treatments-section {
        margin-top: 20px;
        padding-top: 15px;
    }

    .modal-actions {
        margin-top: 20px;
        padding: 0;
        padding-bottom: 20px;
    }

    .modal-actions button {
        padding: 12px;
        font-size: 14px;
    }

    .bottom-panel-content {
        padding: 14px 16px;
    }

    .plant-name {
        font-size: 15px;
    }

    .plant-variety {
        font-size: 12px;
    }

    .add-plant-btn {
        padding: 8px 12px;
        font-size: 13px;
    }

    .map-actions {
        gap: 8px;
    }

    .map-actions button {
        padding: 12px;
        font-size: 14px;
    }
}

/* Loading indicator */
.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 20px 40px;
    border-radius: 8px;
    z-index: 2000;
    display: none;
}

.loading.active {
    display: block;
}

/* Info display */
.info-display {
    background: #f8f9fa;
    padding: 10px;
    border-radius: 6px;
    font-size: 12px;
    color: #7f8c8d;
    display: flex;
    align-items: center;
    gap: 8px;
}

.save-status {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2ecc71;
    transition: background 0.3s;
}

.save-status.saving {
    background: #f39c12;
    animation: pulse 1s infinite;
}

.save-status.error {
    background: #e74c3c;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Action row for mobile */
.action-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 10px;
}

.action-buttons {
    display: flex;
    gap: 5px;
}

/* Bottom Panel */
.bottom-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    z-index: 100;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
}

.bottom-panel.visible {
    transform: translateY(0);
}

.bottom-panel-content {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    cursor: pointer;
    min-height: 60px;
}

.plant-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.plant-name {
    font-size: 16px;
    font-weight: 600;
    color: #2c3e50;
}

.plant-variety {
    font-size: 13px;
    color: #7f8c8d;
}

.add-plant-btn {
    background: #27ae60;
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.add-plant-btn:hover {
    background: #229954;
    transform: translateY(-2px);
}

/* Desktop sidebar info panel */
.sidebar-info-panel {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 12px;
    margin-top: 10px;
    display: none;
}

.sidebar-info-panel.visible {
    display: block;
}

.sidebar-info-panel .plant-name {
    font-size: 14px;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 4px;
}

.sidebar-info-panel .plant-variety {
    font-size: 12px;
    color: #7f8c8d;
    margin-bottom: 8px;
}

.sidebar-info-panel button {
    width: 100%;
    padding: 8px;
    font-size: 13px;
}

.map-info-section {
    margin-bottom: 20px;
}

.map-info-item {
    margin-bottom: 15px;
}

.map-info-item label {
    display: block;
    font-weight: 600;
    color: #555;
    margin-bottom: 5px;
    font-size: 14px;
}

.map-filename {
    display: block;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
    color: #2c3e50;
    font-size: 14px;
    word-break: break-all;
}

.map-name-input {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.map-name-input:focus {
    outline: none;
    border-color: #3498db;
}

.map-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.map-actions button {
    width: 100%;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .map-actions {
        gap: 8px;
    }

    .map-actions button {
        padding: 12px;
        font-size: 14px;
    }
}
